Search code examples
androidandroid-intentmime-typessend

Problems passing a file to another Android app


Extremely weird behaviour, I'm fairly new to Android, but I'm generating some json (first line below) and I'm trying to send it to an application whose manifest says it accepts anything with type "application/xctsk".

The generated file is fine, but the app chooser doesn't offer that application. I can still share the file to Whatsapp and it will be fine, content-wise. However, I still can't open it from Whatsapp. Meanwhile I can

  • open the file manually
  • open other files from other sources, from Whatsapp

Receiving app's Manifest

             <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:mimeType="application/xctsk"
                android:host="*"/>
                <data android:scheme="http"/>
                <data android:scheme="https"/>
                <data android:scheme="content"/>
                <data android:scheme="file"/>
            </intent-filter>

My code

 Uri xctskURI= saveTask(somejson);
 Intent shareIntent = new Intent();
 shareIntent.setAction(Intent.ACTION_SEND);
 shareIntent.putExtra(Intent.EXTRA_STREAM, xctskURI);
 shareIntent.setType("application/xctsk");
 shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
 startActivity(Intent.createChooser(shareIntent, "Send to XCTrack"));

Solution

  • The receiving app supports only ACTION_VIEW. You are using ACTION_SEND. These don't match. Either change your sending app to use ACTION_VIEW or change the receiving app so that it supports ACTION_SEND.