为了账号安全,请及时绑定邮箱和手机立即绑定

Intent Filter 提供不存在的文件路径

Intent Filter 提供不存在的文件路径

浮云间 2023-05-17 14:49:32
我正在创建一个必须从 WhatsApp 导出聊天功能接收 txt 文件的应用程序。我用一个意图过滤器完成了这个,我得到了一个路径“content:/com.whatsapp.provider.media/export-chat/(phone-number)@s.whatsapp.net 我把它作为一个文件,当我尝试阅读它,它不在那里。它给出了 FileNotFound 异常。这是意图过滤器<activity android:name="app.app.whatsanalitycs.Recibir">            <intent-filter>                <action android:name="android.intent.action.SEND"/>                <action android:name="android.intent.action.SEND_MULTIPLE"/>                <category android:name="android.intent.category.APP_EMAIL"/>                <category android:name="android.intent.category.APP_MESSAGING"/>                <category android:name="android.intent.category.DEFAULT"/>                <category android:name="android.intent.category.BROWSABLE"/>                <data android:mimeType="text/*" />            </intent-filter>        </activity>这是当有人从 whatsapp 调用 intent-filter 时调用的 onCreate 函数@Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        TextView text = findViewById(R.id.hola);        TextView text2 = findViewById(R.id.hola2);        Intent intent = getIntent();        String action = intent.getAction();        String type = intent.getType();        text.setText(intent.getDataString());        Bundle bundle = intent.getExtras();        ArrayList a = (ArrayList) bundle.get(Intent.EXTRA_STREAM);        Uri uri = (Uri) a.get(0);        File file = new File(uri.toString());        text2.setText(file.getParent());    }我一直在检查其他使用 Intent 过滤器的应用程序,文件路径应具有以下格式:“content://com.whatsapp.provider.media/item/(somenum)” 我知道这一点是因为我试图通过以下方式发送导出的聊天记录whatsapp,这就是保存它的 url。我不知道问题是出在意图过滤器上,还是出在我如何读取接收到的意图上。
查看完整描述

1 回答

?
红糖糍粑

TA贡献1815条经验 获得超6个赞

我得到一条路径“content:/com.whatsapp.provider.media/export-chat/(phone-number)@s.whatsapp.net

那是一个Uri。具体来说,它是一个来自ContentProvider.

我把它作为一个文件

它不是一个文件。这是一个Uri

使用ContentResolveropenInputStream()读入与之关联的内容Uri


查看完整回答
反对 回复 2023-05-17
  • 1 回答
  • 0 关注
  • 100 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信