将文件传递给另一个 Android 应用程序时出现问题

Problems passing a file to another Android app

非常奇怪的行为,我是 Android 的新手,但我正在生成一些 json(下面的第一行),并且我正在尝试将其发送到清单的应用程序说它接受类型为 "application/xctsk".

的任何内容

生成的文件没问题,但应用程序选择器不提供该应用程序。我仍然可以将文件共享到 Whatsapp,就内容而言,它会很好。但是,我仍然无法从 Whatsapp 打开它。 同时我可以

正在接收应用的清单

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

我的代码

 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"));

接收应用仅支持ACTION_VIEW。您正在使用 ACTION_SEND。这些不匹配。将您的发送应用程序更改为使用 ACTION_VIEW 或更改接收应用程序以使其支持 ACTION_SEND.

原来是很严格的,resolver不满意少了一个完美的匹配。 所有类别都必须匹配。并且出于某些原因,设置 MIME 类型会删除数据。

Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_VIEW);
shareIntent.addCategory(Intent.CATEGORY_DEFAULT);
shareIntent.addCategory(Intent.CATEGORY_BROWSABLE);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

shareIntent.setDataAndType(xctskURI,"application/xctsk");
startActivity(Intent.createChooser(shareIntent, "Send to XCTrack"));