Skip to content

Commit

Permalink
multiply permissions request
Browse files Browse the repository at this point in the history
  • Loading branch information
tiromansev committed Dec 14, 2017
1 parent 898c77f commit 8ce66a2
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 99 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package="com.tiromansev.permissionmanager.example">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PermissionsManager.get().checkWriteExternalAccess(new PermissionsManager.PermissionCallback() {
PermissionsManager.get().checkPermissions(new PermissionsManager.PermissionCallback() {
@Override
public void permissionAccepted() {
Toast.makeText(MainActivity.this, getString(R.string.message_permission_accepted), Toast.LENGTH_LONG).show();
Expand All @@ -29,7 +29,7 @@ public void permissionAccepted() {
public void permissionRejected() {
Toast.makeText(MainActivity.this, getString(R.string.message_permission_rejected), Toast.LENGTH_LONG).show();
}
});
}, PermissionsManager.WRITE_EXTERNAL_REQUEST, PermissionsManager.CAMERA_REQUEST);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
public class PermissionRequestActivity extends AppCompatActivity {

private static final String PERMISSIONS_KEY = "permissions";
private static final String PERMISSIONS_REQUEST = "PERMISSIONS_REQUEST";
private static final int PERMISSIONS_REQUEST = 99;
private static final String MESSAGE = "MESSAGE";
private static final String RATIONALE_MESSAGE = "RATIONALE_MESSAGE";

static Intent getRequestIntent(Context context, int requestCode, String rationaleMessage, String... permissions) {
static Intent getRequestIntent(Context context, String rationaleMessage, String... permissions) {
Intent intent = new Intent(context, PermissionRequestActivity.class);
intent.putExtra(PERMISSIONS_KEY, permissions);
intent.putExtra(PERMISSIONS_REQUEST, requestCode);
intent.putExtra(RATIONALE_MESSAGE, rationaleMessage);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
return intent;
Expand All @@ -45,7 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
handleIntent(getIntent());
return;
}
finish();
close();
}

@Override
Expand All @@ -71,7 +70,6 @@ private void handleIntent(Intent intent) {
String rationaleMessage = intent.getStringExtra(RATIONALE_MESSAGE);
if (message == null) {
final String[] permissions = intent.getStringArrayExtra(PERMISSIONS_KEY);
final int requestCode = intent.getIntExtra(PERMISSIONS_REQUEST, 0);
if (rationaleMessage != null) {
AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.AppCompatAlertDialogStyle);
dialog.setTitle(null);
Expand All @@ -82,13 +80,13 @@ private void handleIntent(Intent intent) {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
PermissionsManager.get().markRequestedPermissionsAsAsked();
ActivityCompat.requestPermissions(PermissionRequestActivity.this, permissions, requestCode);
ActivityCompat.requestPermissions(PermissionRequestActivity.this, permissions, PERMISSIONS_REQUEST);
}
});
dialog.show();
}
else {
ActivityCompat.requestPermissions(this, permissions, requestCode);
ActivityCompat.requestPermissions(this, permissions, PERMISSIONS_REQUEST);
}
}
else {
Expand Down Expand Up @@ -131,7 +129,7 @@ private void close() {

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
PermissionsManager.get().onRequestPermissionsResult(requestCode);
close();
PermissionsManager.get().onRequestPermissionsResult(permissions);
}
}
Loading

0 comments on commit 8ce66a2

Please sign in to comment.