Android 6(23) - 未请求许可

问题描述 投票:2回答:5

我坚持使用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

它说该应用程序不需要任何许可。

我该怎么解决呢?

非常感谢任何建议。

android android-6.0-marshmallow android-permissions permission-denied
5个回答
4
投票

它说该应用程序不需要任何许可。

那是正确的。您应用页面的该部分列出了dangerous权限。没有人有protectionLeveldangerous

我该怎么解决呢?

没有什么不对,所以没有什么可以解决的。


2
投票

正如@Saini所说,从Android 6.0(API级别23)开始,用户在应用程序运行时向应用程序授予权限,而不是在安装应用程序时。但是如果您选择低于23的targetSdkVersion,您的应用程序将被视为与之前一样,并且会要求用户在他们想要安装应用程序时授予该应用程序的权限。你可以从here了解更多


2
投票

在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中声明这些权限,它就可以正常工作。无需检查上面列出的权限,因为它无法撤销。


1
投票

从Android 6.0(API级别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.
    }
}

© www.soinside.com 2019 - 2024. All rights reserved.