Search code examples
androidandroid-intentandroid-contentproviderandroid-permissionsandroid-fileprovider

How to fetch txt file from whatsapp fileprovider


I trying to get whatsapp chat txt file. As i saw on Android documentation:

private void handleSentMultipleAttached(Intent intent) {
    ArrayList<Uri> attachedFilesUris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
    if (attachedFilesUris != null) {
        for (Uri uri : attachedFilesUris) {
            File f = new File(uri.getPath());
        }
    }
}

The uri is:

content://com.whatsapp.fileprovider/external/.Shared/WhatsApp%20Chat%20with.txt

But i can't use the f file because file is not exist in that path.

I'v already open permission in the manifest:

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_USER_DICTIONARY" />

What should i do so i can use the file?


Solution

  • But i can't use the f file because file is not exist in that path.

    That is not a filesystem path. That is a content: Uri from a ContentProvider.

    What should i do so i can use the file?

    It is not a file, any more than this Web page is a file on the Stack Overflow Web server.

    You can use a ContentResolver and openInputStream() to get an InputStream on the content represented by that Uri. You can get a ContentResolver by calling getContentResolver() on a Context, such as an Activity or Service.