【问题标题】:Android 6 (23) - no permission requestedAndroid 6 (23) - 未请求权限
【发布时间】:2016-11-12 01:53:53
【问题描述】:

我在 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...

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

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

请问如何解决?

非常感谢您的建议。

【问题讨论】:

    标签: android android-6.0-marshmallow android-permissions permission-denied


    【解决方案1】:

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

    没错。您应用页面的该部分列出了dangerous 权限。你没有一个有protectionLeveldangerous

    请问如何解决?

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

    【讨论】:

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

      【讨论】:

      【解决方案3】:

      正如@Saini 所说,从 Android 6.0(API 级别 23)开始,用户在应用运行时授予应用权限,而不是在安装应用时。 但是如果您选择 targetSdkVersion 低于 23,您的应用程序将像以前一样被处理,并会在用户要安装应用程序时要求用户授予该应用程序的权限。你可以从here阅读更多内容

      【讨论】:

        【解决方案4】:

        从 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.
            }
        }
        

        【讨论】:

          【解决方案5】:

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2016-05-28
            • 1970-01-01
            • 1970-01-01
            • 2022-11-19
            • 2016-12-14
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多