繁体   English   中英

Ionic 3,当请求访问设备上的照片,媒体和文件的权限时,没有启动屏幕

[英]Ionic 3, no splashscreen when permissions are requested to access photos, media and files on the device

嗨,我正在使用Ionic 3构建应用程序,当请求权限时,我偶然发现了一个与SplashScreen有关的问题。

确切地说,权限弹出窗口显示以下消息:

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

当应用程序需要权限时,该应用程序的第一次运行时不会显示启动画面。 使用custom-config-plugin启动画面删除权限后,将永远不会显示该画面。

所需的行为是在启动应用程序时不请求权限,而在实际需要时请求权限。

我使用了默认的离子应用程序(标签主题)来尽可能地对其进行解释。

(演示)应用程序有3个不同的状态:

  1. 当我拥有needs no permissions的应用程序时,SplashScreen会as expected

  2. 通过添加需要permissions的插件,在应用程序的first run时会出现一个request框,但此后no splashscreen 尽管以防万一我后来kill and re-run该应用程序,但SplashScreen的行为as expected

  3. 然后,我尝试remove the permissions (因此在第一次运行时不要求它们),并尝试在实际需要它们时请求它们,具体取决于用户为获得更好的用户体验而采取的措施。 我使用了custom-config-plugin (' https://github.com/dpa99c/cordova-custom-config '),并设法拥有与状态#1 exact same AndroidManifest.xml (在platform / android中)文件。 结果是启动屏幕永远不会在应用程序的任何运行中显示。

综上所述,当插件需要权限时,仅在首次运行时没有启动屏幕。 如果我尝试使用custom-config-plugin删除上述权限,则不会显示启动屏幕。

是否有关于如何管理的建议:

1.有启动画面

2.启动应用程序时没有权限请求(而插件停留并在需要时处理权限)?

下面,我按状态包括文件AndroidManifest.xml:

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(与#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>

最简单的方法是不在清单中声明权限,因为清单是在构建过程中生成的,因此会立即请求权限。

当需要在命令中使用权限时,尝试直接从代码中请求权限:

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

这应该提示用户输入权限,而不会影响您的初始屏幕。 有关动态请求权限的更多信息,请参见: 运行时请求权限

(这是我在这里的第一个答案,因此,如果您需要更多帮助或我的答案不清楚,请告诉我)

希望这可以帮助!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM