android - Cordova APK 首次运行时不请求权限

标签 android cordova permissions apk

我是 Android 开发新手。我尝试在 Cordova 中构建 APK,但在第一个应用程序运行时它不要求任何权限,因此工作不正确。以前的开发人员已经构建了它,我有他的 APK,它在第一次运行时要求权限。

我做错了什么?有什么想法吗?

以下是我的配置和 list :

配置:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.ettractions" version="1.4.3" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>Ettractions</name>
    <description>
        Ettractions application.
    </description>
    <author email="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2a4f48595f5a5a45585e6a4f5e5e584b495e4345445904494547" rel="noreferrer noopener nofollow">[email protected]</a>" href="http://ettractions.com">
        Ettractions Team
    </author>
    <preference name="permissions" value="none" />
    <preference name="orientation" value="landscape" />
    <preference name="target-device" value="universal" />
    <preference name="fullscreen" value="true" />
    <preference name="webviewbounce" value="true" />
    <preference name="splash-screen-duration" value="0" />
    <preference name="prerendered-icon" value="true" />
    <preference name="stay-in-webview" value="false" />
    <preference name="ios-statusbarstyle" value="black-opaque" />
    <preference name="detect-data-types" value="true" />
    <preference name="exit-on-suspend" value="false" />
    <preference name="show-splash-screen-spinner" value="true" />
    <preference name="auto-hide-splash-screen" value="true" />
    <preference name="disable-cursor" value="false" />
    <preference name="android-minSdkVersion" value="19" />
    <preference name="android-installLocation" value="auto" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    <gap:plugin name="org.apache.cordova.battery-status" />
    <gap:plugin name="org.apache.cordova.camera" />
    <gap:plugin name="org.apache.cordova.media-capture" />
    <gap:plugin name="org.apache.cordova.console" />
    <gap:plugin name="org.apache.cordova.contacts" />
    <gap:plugin name="org.apache.cordova.device" />
    <gap:plugin name="org.apache.cordova.device-motion" />
    <gap:plugin name="org.apache.cordova.device-orientation" />
    <gap:plugin name="org.apache.cordova.dialogs" />
    <gap:plugin name="org.apache.cordova.file" />
    <gap:plugin name="org.apache.cordova.file-transfer" />
    <gap:plugin name="org.apache.cordova.geolocation" />
    <gap:plugin name="org.apache.cordova.globalization" />
    <gap:plugin name="org.apache.cordova.inappbrowser" />
    <gap:plugin name="org.apache.cordova.media" />
    <gap:plugin name="org.apache.cordova.network-information" />
    <gap:plugin name="org.apache.cordova.splashscreen" />
    <gap:plugin name="org.apache.cordova.vibration" />
    <icon src="icon.png" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <plugin name="cordova-plugin-file" spec="~6.0.2" />
    <plugin name="cordova-plugin-file-transfer" spec="~1.7.1" />
</widget>

list :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.phonegap.ettractions"
    android:hardwareAccelerated="true"
    android:versionCode="10403"
    android:versionName="1.4.3" >

    <uses-sdk
        android:minSdkVersion="19"
        android:targetSdkVersion="28" />

    <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" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.WRITE_CONTACTS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-feature android:name="android.hardware.location.gps" />

    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.VIBRATE" />

    <application
        android:debuggable="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true" >
        <activity
            android:name="com.phonegap.ettractions.MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
            android:label="@string/activity_name"
            android:launchMode="singleTop"
            android:screenOrientation="landscape"
            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>

        <provider
            android:name="org.apache.cordova.camera.FileProvider"
            android:authorities="com.phonegap.ettractions.provider"
            android:exported="false"
            android:grantUriPermissions="true" >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/camera_provider_paths" />
        </provider>
    </application>

</manifest>

最佳答案

自 Android 6.0 起,安装或首次运行时不再自动询问权限。 您必须在 list 中声明要使用哪些权限,并且需要时手动向用户询问权限。

例如,该应用程序有很多屏幕,但只有一个屏幕使用地理定位。最好仅在用户访问该屏幕时请求位置权限,而不是在首次运行时请求位置权限。这就是为什么现在必须手动请求权限的原因。

使用 Cordova 时,您无法直接调用 Android 函数来请求权限,而必须使用插件。

引用:Android permission documentation

You declare that your app needs a permission by listing the permission in the app manifest and then requesting that the user approve each permission at runtime (on Android 6.0 and higher).

您可能还想查看有关如何请求权限的示例插件:https://github.com/NeoLSN/cordova-plugin-android-permissions

关于android - Cordova APK 首次运行时不请求权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60953859/

相关文章:

javascript - phonegap 离线/在线事件不工作

extjs - 如何在extjs中设计权限和条件加载

android - 微调器无法显示来自 SD 卡的数据

javascript - AVG(COLUMN_SCORE) 未写入 SQLite 数据库

cordova - 需要帮助部署 Windows 8 PhoneGap 应用程序

javascript - JavaScript 中的大变量 - 让它们成为全局变量?

PHP代码通过权限限制成员访问

ssh - 由于您的组,如何确定您是否可以使用 SFTP 写入目录?

android - 在 Android Gallery 中选择多张图片

android - 为 android x86 & x86_64 架构编译 ijkplayer x264,错误 : unknown type name 'v4si'