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

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

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,REQUEST_READ_PHONE_STATE);

}

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值