1

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?

motis10
  • 2,484
  • 1
  • 22
  • 46

1 Answers1

2

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • You can expand your explanation? – motis10 Jun 16 '16 at 22:34
  • @motis10: Well, there is [this blog post](https://commonsware.com/blog/2016/03/15/how-consume-content-uri.html) and [the documentation for `openInputStream()`](https://developer.android.com/reference/android/content/ContentResolver.html#openInputStream(android.net.Uri)) and [some documentation on using a `Uri`](https://developer.android.com/guide/topics/providers/document-provider.html#open-client). Otherwise, please feel free to explain what you do not understand. – CommonsWare Jun 16 '16 at 22:40