Intent Filter giving file path that does not exist

I’m creating an app that has to recive a txt file from WhatsApp export chat function.

I have done this with an intent filter, and i get a path “content:/com.whatsapp.provider.media/export-chat/(phone-number)@s.whatsapp.net I get it as a file, and when i try to read it, its not there. It gives a FileNotFound exception.

This is the intent filter

<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>

This is the onCreate function that is called when someone calls the intent-filter from whatsapp

@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());
    }

I have been checking other apps that use intent filters and the file path should have this format: “content://com.whatsapp.provider.media/item/(somenum)”
I know this because i tried to send the exported chat through whatsapp and thats the url where it is saved.
I don’t know if the problem is with the intent filter or with how im reading the intent that is recived.

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

and i get a path “content:/com.whatsapp.provider.media/export-chat/(phone-number)@s.whatsapp.net

That is a Uri. Specifically, it is one from a ContentProvider.

I get it as a file

It is not a file. It is a Uri.

Use ContentResolver and openInputStream() to read in the content associated with that Uri.