Android 12 API 31
I've been writing an Android App and one step at a time building it to my spec. Now, I am running into an issue.
One of the feature my app will have is emailing an image with a click of a button. So, I had to setup FileProvider to hide the DIRECT image file PATH before sending it out. One of the step in doing this is to include this FileProvider info in my manifest.xml as shown below.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:dist="http://schemas.android.com/apk/distribution"
package="com.example.MyApp" >
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<dist:module dist:instant="true" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp"
android:usesCleartextTraffic="true" >
<activity
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true" >
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths" />
</provider>
</application>
However, I noticed right after doing so and running/installing/debugging successfully that my app acted unlike before;
My app ICON is not found within "Apps Icon" screen.
Under App Info window for my app, open button is missing as shown below with FileProvider code.
If I remove the FileProvider option from manifest.xml, Open button along with uninstall and force stop is displayed and active as shown below.
Otherwise, my app installs and runs with no issues, but the only time I have access is when it runs and the main activity is displayed automatically. If I close it, I have no way of starting it again, unless I rerun my code from Android Studio. So, what is the reason for this in regards to FileProvider?
So, what is the reason for this in regards to FileProvider?
It has nothing to do with FileProvider
. It has everything to do with this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SEND" />
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
This will only match an Intent
that:
<action>
values; andLAUNCHER
; and,Uri
with a mailto
schemeNothing is going have that combination. In particular, launchers won't find your activity, because the Intent
that they use does not have mailto
.
Instead, you need three separate <intent-filter>
elements:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
The first <intent-filter>
will cause this activity to be picked up by launchers. Your third <intent-filter>
probably should have a <data>
element specifying the MIME type (or pattern) that you wish to support, but I do not know what that would be.