我正在创建一个必须从WhatsApp Export Chat功能恢复TXT文件的应用程序。
我已经使用了一个意图过滤器来完成此操作,并且我得到了一条路径" content:/com.whatsapp.provider.media/export-chat/(phore-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
时称为的功能@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());
}
我一直在检查其他使用意图过滤器的应用程序,并且文件路径应具有此格式:" content://com.whatsapp.provider.media/item/(somenum("我之所以知道这一点,是因为我试图通过WhatsApp发送导出的聊天,这就是保存的URL。我不知道问题是否在于意图过滤器或即时阅读的收看意图。
我得到了一条路径" content:/com.whatsapp.provider.media/export-chat/(phone-number(@s.whatsapp.net
那是Uri
。具体来说,它是ContentProvider
。
我将其作为文件
它不是文件。它是Uri
。
使用ContentResolver
和openInputStream()
在与该Uri
相关的内容中读取。