安卓6(23)- 未请求权限

4

我遇到了Android 6中的新权限模型问题。

我在清单文件中定义了以下权限:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>

<application...

但是,如果我在模拟器中启动应用程序并打开应用程序详细信息,我会看到以下内容:

enter image description here

它说该应用程序不需要任何权限。

请问我该如何解决?

非常感谢您的任何建议。

5个回答

6

它说应用程序不需要任何权限。

这是正确的。您的应用程序页面中的这部分列出了“危险”权限。 您的权限没有任何一个具有“危险”的 protectionLevel

我该如何解决呢?

没有问题,因此没有什么需要解决的。


4

在 Android 6.0 之前,有一些权限在安装时会自动授予,并且无法撤销。我们称之为普通权限 (PROTECTION_NORMAL)。以下是完整列表:

android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
android.permission.ACCESS_NETWORK_STATE
android.permission.ACCESS_NOTIFICATION_POLICY
android.permission.ACCESS_WIFI_STATE
android.permission.ACCESS_WIMAX_STATE
android.permission.BLUETOOTH
android.permission.BLUETOOTH_ADMIN
android.permission.BROADCAST_STICKY
android.permission.CHANGE_NETWORK_STATE
android.permission.CHANGE_WIFI_MULTICAST_STATE
android.permission.CHANGE_WIFI_STATE
android.permission.CHANGE_WIMAX_STATE
android.permission.DISABLE_KEYGUARD
android.permission.EXPAND_STATUS_BAR
android.permission.FLASHLIGHT
android.permission.GET_ACCOUNTS
android.permission.GET_PACKAGE_SIZE
android.permission.INTERNET
android.permission.KILL_BACKGROUND_PROCESSES
android.permission.MODIFY_AUDIO_SETTINGS
android.permission.NFC
android.permission.READ_SYNC_SETTINGS
android.permission.READ_SYNC_STATS
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.REORDER_TASKS
android.permission.REQUEST_INSTALL_PACKAGES
android.permission.SET_TIME_ZONE
android.permission.SET_WALLPAPER
android.permission.SET_WALLPAPER_HINTS
android.permission.SUBSCRIBED_FEEDS_READ
android.permission.TRANSMIT_IR
android.permission.USE_FINGERPRINT
android.permission.VIBRATE
android.permission.WAKE_LOCK
android.permission.WRITE_SYNC_SETTINGS
com.android.alarm.permission.SET_ALARM
com.android.launcher.permission.INSTALL_SHORTCUT
com.android.launcher.permission.UNINSTALL_SHORTCUT

只需在AndroidManifest.xml中声明这些权限,它就能正常工作。无需检查上述权限是否被撤销。


谢谢,已点赞。此外,在这里添加了新旧版本的比较:https://dev59.com/j5jga4cB1Zd3GeqPPMh_#55118424 - Manohar Reddy Poreddy

3
根据@Saini所说,自Android 6.0(API级别23)开始,在应用程序运行时,用户会授予应用程序权限,而不是在安装应用程序时授予权限。 但是,如果您选择的targetSdkVersion低于23,则您的应用程序将像以前一样处理,并且将要求用户在安装应用程序时授予权限。您可从这里了解更多信息。

3

2
从Android 6.0 (API level 23)开始,用户在应用程序运行时授予权限,而不是在安装应用程序时授权。这种方法简化了应用程序的安装过程,因为用户无需在安装或更新应用程序时授予权限。它还使用户对应用程序的功能有更多的控制权;例如,用户可以选择给相机应用程序访问相机但不允许访问设备位置。用户可以随时通过进入应用程序的设置屏幕来撤销权限。
更多信息请参见:https://developer.android.com/training/permissions/requesting.html https://developer.android.com/training/permissions/declaring.html https://developer.android.com/training/permissions/best-practices.html
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {

        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

    } else {

        // No explanation needed, we can request the permission.

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

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接