0

Hi I am building an app using ionic 3 and I have stumbled upon an issue regarding SplashScreen when permissions are requested.

To be exact, the permission pop-up displays the following message:

Allow $APPNAME to access photos, media, and files on your device?

When an app requires permissions, there is no splashscreen at the first run of the app. When the permissions are removed using the custom-config-plugin splashscreen is never displayed.

The desired behaviour is to not request permissions when the app is started, but request them when they are actually needed.

I've used a default ionic app (tabs theme) to explain it as best as possible.

There are 3 distinct states of the (demo) app:

  1. When I have an app that needs no permissions the SplashScreen acts as expected.

  2. By adding a plugin that requires permissions, there is a request box at the first run of the app, but there is no splashscreen after. Although in case I kill and re-run the app afterwards, the SplashScreen acts as expected.

  3. Then I tried to remove the permissions (so they are not requested at the first run), and try to request them when they are actually needed, depending on the user's actions for better UX. I used the custom-config-plugin ('https://github.com/dpa99c/cordova-custom-config') and managed to have the exact same AndroidManifest.xml (in platforms/android) file as in state #1. The result was that splash screen is never shown at any run of the app.

To sum it up, when a plugin requires permissions, there is no splash screen at the first run only. If I try to use the custom-config-plugin to remove said permissions, splash screen is never displayed.

Are there any suggestions on how to manage to:

1.have splash screen

2.not have a request for permissions when starting the app (while the plugin stays and permissions are handled when needed) ?

Below I include the file AndroidManifest.xml per state:

1

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
</manifest>

2

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

3 (Identical to #1)

<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="0.0.1" package="io.ionic.starter" xmlns:android="http://schemas.android.com/apk/res/android">
    <supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application android:hardwareAccelerated="true" android:icon="@mipmap/icon" android:label="@string/app_name" android:supportsRtl="true">
        <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="MainActivity" android:theme="@android:style/Theme.DeviceDefault.NoActionBar" android:windowSoftInputMode="adjustResize">
            <intent-filter android:label="@string/launcher_name">
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="16" android:targetSdkVersion="26" />
</manifest>
George
  • 426
  • 5
  • 6

1 Answers1

1

The easiest way to do this is to not declare the permission inside the manifest, because the manifest is generated as part of the build process and therefore will ask for permissions right away.

Instead try asking for permissions directly from your code when you need to use them with the command:

ActivityCompat.requestPermissions(thisActivity,
            new String[]{Manifest.permission.READ_CONTACTS},
            MY_PERMISSIONS_REQUEST_READ_CONTACTS);

This should prompt the user for permissions, without affecting your splash screen. For more information of requesting permissions dynamically see: Requesting Permissions at Run Time.

(This is my first answer on here so let me know if you need more help or if my answer is not clear)

Hope this helps!

  • This would help me if there was a native app at hand. But this is an ionic cordova application, not a native one. On top of that, AndroidManifest.xml at states #1 and #3 do not include said permission – George Jan 17 '18 at 08:56
  • Ahhhh I understand now, sadly I don't know much about ionic cordova but in my travels I came across [link](https://stackoverflow.com/a/47650104/9220124) that may or may not help you. Apologies for the misunderstanding – Matthew Flathers Jan 17 '18 at 13:16