kitkat 上未显示请求许可
Ask Permission not shown on kitkat
我正在了解运行时请求权限。我的 phone OS 是奇巧。这是我的代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ActivityCompat.requestPermissions(this, arrayOf("com.android.launcher.permission.INSTALL_SHORTCUT"), 1000)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1000) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//do something
}
}
}
但未显示权限对话框。我的代码有没有错误?
您不能在Android 6.0
以下请求运行时权限
低于Android 6.0 用户安装应用程序时授予所有权限
仅供参考
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app
Android 开发者网站报价,
In Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
运行时间权限添加到AndroidMarshmallow。 Android marshmallow 之前的版本将在应用安装期间请求许可。
检查 this 以了解有关 android 运行时权限的更多信息
奇巧(第 20 版)
Android或以下版本不需要运行时权限请求,您只需在AndroidManifest.xml
文件中定义权限即可。
示例:<uses-permission android:name="android.permission.CAMERA"/>
但是
对于 Lollipop(版本 21)或更高版本,您需要添加方法来为您的应用程序请求权限。
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
这意味着您的 phone 需要从 API level-23 请求运行时权限,即 Marshmallow,而 KitKat 是 API level-19。因此,操作系统不会请求任何运行时权限。
我正在了解运行时请求权限。我的 phone OS 是奇巧。这是我的代码:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
ActivityCompat.requestPermissions(this, arrayOf("com.android.launcher.permission.INSTALL_SHORTCUT"), 1000)
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == 1000) {
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
//do something
}
}
}
但未显示权限对话框。我的代码有没有错误?
您不能在Android 6.0
以下请求运行时权限低于Android 6.0 用户安装应用程序时授予所有权限
仅供参考
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app
Android 开发者网站报价,
In Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
运行时间权限添加到AndroidMarshmallow。 Android marshmallow 之前的版本将在应用安装期间请求许可。
检查 this 以了解有关 android 运行时权限的更多信息
奇巧(第 20 版)
Android或以下版本不需要运行时权限请求,您只需在AndroidManifest.xml
文件中定义权限即可。
示例:<uses-permission android:name="android.permission.CAMERA"/>
但是
对于 Lollipop(版本 21)或更高版本,您需要添加方法来为您的应用程序请求权限。
Beginning in Android 6.0 (API level 23), users grant permissions to apps while the app is running, not when they install the app.
这意味着您的 phone 需要从 API level-23 请求运行时权限,即 Marshmallow,而 KitKat 是 API level-19。因此,操作系统不会请求任何运行时权限。