我想一次授予多个权限.....这是我的代码..这只是我想一次授予多个权限的示例..
public class MainActivity extends Activity {
public static final int R_PERM = 123;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.data);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
if ((CheckPermission(this, Manifest.permission.CAMERA))&&
(CheckPermission(this, Manifest.permission.READ_PHONE_STATE))&&
(CheckPermission(this, Manifest.permission.NFC)))
{
PermHandling();
}
else {
RequestPermission(MainActivity.this, Manifest.permission.CAMERA, R_PERM);
RequestPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE, R_PERM );
RequestPermission(MainActivity.this, Manifest.permission.NFC, R_PERM );
//NewPermHandling();
}
}
private void PermHandling() {
//My app internal parts....
//Here my stuff works...
}
//private void NewPermHandling(){
//}
@Override
public void onRequestPermissionsResult(int permsRequestCode, String[] permissions, int[] grantResults) {
switch (permsRequestCode) {
case R_PERM: {
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
PermHandling();
} else {
//Toast.makeText(this, "Please Grant Permissions other wise app will close.!", Toast.LENGTH_SHORT).show();
}
return;
}
}
}
public void RequestPermission(Activity thisActivity, String Permission, int Code) {
if (ContextCompat.checkSelfPermission(thisActivity,
Permission)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Permission)) {
} else {
ActivityCompat.requestPermissions(thisActivity,
new String[]{Permission},
Code);
}
}
}
public boolean CheckPermission(Context context, String Permission) {
if (ContextCompat.checkSelfPermission(context,
Permission) == PackageManager.PERMISSION_GRANTED) {
return true;
} else {
return false;
}
}
}
在这里,我一一授予权限所以我在运行时一一获得权限请建议我一次授予所有权限..
请在我的代码上建议我应该在哪里更改..
在这里,我是我的应用程序,我需要立即授予更多权限,例如相机,位置,存储等...请在 Mycode 上建议我...。
更新 和所有权限应立即使用“不再询问”检查按钮...。
请在我的代码中建议我这种类型的,,,,