'Whatsapp doesn't detect the mime type of file sent through intent
I have implemented the export/share feature in my app and the file being exported to / shared between other apps is a custom mime type of .tmly that I created. When I use the code below to share the file Uri, WhatsApp detects the file as a .bin and not a .tmly file extension, therefore, when I click on the file sent to Whatsapp, it doesn't show my app in the list that opens a .bin file. Actually, when I send the file from another app, Whatsapp detects it as a .tmly file and whenever I click on the file sent to Whatsapp, my app shows in the Android Sharesheet or chooser as one of the apps that can open up the file. Code that performs the action below:
// opens up chooser, used to send send the Uri of the exported file
btn_share.setOnClickListener(v -> {
Intent shareIntent = new Intent(Intent.ACTION_SEND);
if (file.exists()) {
String shareTextSubject = getString(R.string.share_text_subject_1);
shareIntent.setDataAndType(fileUri, "application/tmly");
shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareTextSubject);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareTextSubject);
shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(shareIntent, getString(R.string.share_text_subject_2)));
} else {
Toast.makeText(getActivity(), R.string.no_share_subject_text, Toast.LENGTH_SHORT).show();
}
});
I will also add the part in my Manifest.xml file that declares the activity to open up the file.
<activity
android:name=".exports.ImportResultsActivity"
android:exported="true"
android:priority="1"
android:theme="@style/AppTheme.SlideVertical_recipient">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:host="*" />
<data android:pathPattern=".*\\.tmly" />
<data android:mimeType="*/*" />
</intent-filter>
<!-- Work-around so that TimeLY is able to import data from Whatsapp and MIUI File manager -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain" />
<data android:mimeType="application/vnd.oasis.opendocument.text" />
<data
android:mimeType="application/pdf"
android:scheme="file" />
<data
android:mimeType="application/pdf"
android:scheme="content" />
</intent-filter>
</activity>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
