android权限允许,android – 允许多次运行时权限

 2023-09-11 阅读 18 评论 0

摘要:我正在编写代码,要求在组中的android 6.0上获得多个运行时权限.一切都很好,我为此做了一些很好的例子,但仍然有问题.在ActivityCompat.shouldShowRequestPermissionRationale(context,READ_PHONE_STATE)中,它给出了关于上下文的错误错误的第一个论证背景请帮忙解决问题.提前致

我正在编写代码,要求在组中的

android 6.0上获得多个运行时权限.一切都很好,我为此做了一些很好的例子,但仍然有问题.

在ActivityCompat.shouldShowRequestPermissionRationale(context,READ_PHONE_STATE)中,它给出了关于上下文的错误

错误的第一个论证背景请帮忙解决问题.

提前致谢

代码是:

if (ContextCompat

.checkSelfPermission(SpalshActivity.this,

READ_PHONE_STATE)+ContextCompat.checkSelfPermission(context,

WRITE_EXTERNAL_STORAGE) +ContextCompat.checkSelfPermission(context,

CAMERA) + ContextCompat

.checkSelfPermission(context,

READ_CONTACTS)+ContextCompat

.checkSelfPermission(context,

CALL_PHONE)+ContextCompat

.checkSelfPermission(context,

ACCESS_FINE_LOCATION)+ContextCompat

.checkSelfPermission(context,

READ_SMS)== PackageManager.PERMISSION_GRANTED) {

myMethod();

}

else {

if (ActivityCompat.shouldShowRequestPermissionRationale

(context, READ_PHONE_STATE) ||ActivityCompat.shouldShowRequestPermissionRationale

(context, WRITE_EXTERNAL_STORAGE)||

ActivityCompat.shouldShowRequestPermissionRationale

(context, CAMERA) ||

ActivityCompat.shouldShowRequestPermissionRationale

(context, READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale

(context, CALL_PHONE) || ActivityCompat.shouldShowRequestPermissionRationale

(context, ACCESS_FINE_LOCATION) || ActivityCompat.shouldShowRequestPermissionRationale

(context, READ_SMS)) {

Snackbar.make(findViewById(android.R.id.content),

"Please Grant Permissions",

Snackbar.LENGTH_INDEFINITE).setAction("ENABLE",

new View.OnClickListener() {

@Override

public void onClick(View v) {

ActivityCompat.requestPermissions(SpalshActivity.this,

new String[]{READ_PHONE_STATE,WRITE_EXTERNAL_STORAGE,CAMERA, READ_CONTACTS, CALL_PHONE, ACCESS_FINE_LOCATION, READ_SMS},

REQUEST_READ_PHONE_STATE);

}

}).show();

} else {

ActivityCompat.requestPermissions(SpalshActivity.this,

new String[]{READ_PHONE_STATE,WRITE_EXTERNAL_STORAGE,CAMERA, READ_CONTACTS, CALL_PHONE, ACCESS_FINE_LOCATION, READ_SMS},

REQUEST_READ_PHONE_STATE);

}

}

}

}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/42947.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息