btnMulti.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { checkPermission(); } });
//method
private void checkPermission() { if (ActivityCompat.checkSelfPermission(this, permissionsRequired[0]) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, permissionsRequired[1]) != PackageManager.PERMISSION_GRANTED) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("This app needs Camera and Location permissions."); builder.setTitle("Need Multiple Permissions"); builder.setPositiveButton("Grant", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { ActivityCompat.requestPermissions(MultiplePermissionActivity.this, permissionsRequired, 100); } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); builder.show(); } }
No comments:
Post a Comment