亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 164 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號