Android M permissions close my app

android permissions best practices
read external storage permission android
android-camera permission example
app permissions to avoid
android location permission
how to add permission in android studio
android app restart when change permission

I check for the required permissions on my Log In screen. The dialog shows asking for the 4 permissions I need. All good, but when the dialog appears, the background becomes black and my app closes (doesn't crash, just closes). When I'm done with choosing the permissions I open the app again and it continues running from where it stopped. How can I make the app continue running while the permissions dialog is shown? I use a class which checks for permissions and call it in the Log In activity.

The class:

public abstract class RuntimePermissionsActivity extends AppCompatActivity {
private SparseIntArray mErrorString;

protected void onCreate(@Nullable Bundle savedInstanceState){
    mErrorString = new SparseIntArray();

public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults){
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    int permissionCheck = PackageManager.PERMISSION_GRANTED;
    for (int permission : grantResults){
        permissionCheck = permissionCheck + permission;
    if ((grantResults.length>0) && permissionCheck == PackageManager.PERMISSION_GRANTED){
    else {

                Intent intent = new Intent();
                intent.setData(Uri.parse("package:" + getPackageName()));

public void requestAppPermissions(final String[] requestedPermissions, final int requestCode){
    int stringId = 0;
    mErrorString.put(requestCode, stringId);
    int permissionCheck = PackageManager.PERMISSION_GRANTED;
    boolean shouldShowRequestPermissionRationale = false;
    for (String permission : requestedPermissions){
        permissionCheck = permissionCheck + ContextCompat.checkSelfPermission(this, permission);
        shouldShowRequestPermissionRationale = ActivityCompat.shouldShowRequestPermissionRationale(this, permission);
    if(permissionCheck != PackageManager.PERMISSION_GRANTED){
                    ActivityCompat.requestPermissions(RuntimePermissionsActivity.this, requestedPermissions, requestCode);
        else {
            ActivityCompat.requestPermissions(this, requestedPermissions, requestCode);
            Toast.makeText(RuntimePermissionsActivity.this, "Please relaunch the application in order for the changes to take effect!", Toast.LENGTH_LONG).show();
    else {

public abstract void onPermissionsGranted(int requestCode);

The Log In activity call:

            String[]{Manifest.permission.READ_CONTACTS, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_PERMISSIONS);

An example of implementing Permissions in any Activity.

public class SampleActivity extends AppCompatActivity{
    private final int PERMISSION_CODE = 1;
    Button button;
    onCreate(Bundle savedInstance){
        button = (Button)findViewById(;
        button.setOnClickListener(new OnClickListener(){
            public void onClick(View view){
        //remaining code to continue using the app
        //your actual code should also be in this same class

    private void requestPermissionAndContinue(){
        if(ContextCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED){
            if(ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS)){
                Log.e(TAG, "permission denied, show dialog");
                ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, PERMISSION_CODE);

    private void accessContacts(){
        //your code once you receive permission

    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        if(grantResults.length > 0 && permissions[0]==PackageManager.PERMISSION_GRANTED){
             //redirect to settings page or ask permission again

App permissions best practices, Android 6.0 Marshmallow introduced a new permissions model that lets apps request permissions from the user at runtime, rather than prior to installation. Google was met with a round of applause during their keynote yesterday when they announced Android M would give users more control over the device permissions apps can request. We show you exactly how

I faced same issue,check if activity android:noHistory="true" in your Manifest file.

Request App Permissions, Detecting location · Requesting Permissions · Using the Speaker. Android TV. Overview. Build TV Apps. Overview · Get started with TV apps  This will take you to the new “App permissions” screen. Different categories of permissions each app has—for example, Camera, Contacts, Location, Microphone, Phone, SMS, and Storage—will be displayed here. Older Android apps automatically get these permissions when you install them,

Same problem here.

ankit jain was on the track. Removing android:noHistory="true" fixed the N.Park problem.

Although in my case I needed that value to be true, or at least the behaviour that makes (I had a SplashScreen where I managed the permissions, and after moving on, I wanted that Activity out of my stack).


  1. I deleted line android:noHistory="true"

  2. In the activity I manage the permission without problems

  3. After that, I move into the next activity with:


How to enable or disable App Permissions on the Android M , Those who have flashed the Android M developer preview will be able to start controlling permissions right away, even in apps that haven't  If the user is running Android 6.0 (API level 23) or later, every time the user tries some new app feature that requires a permission, the app has to interrupt the user's work with a permission request.

Remove android:noHistory="true" attribute from respective RuntimePermissionsActivity tag from Android manifest file solved that problem.

How do I revoke the HIDDEN permissions?, I've read on Google NUMEROUS times that I'm in control of my apps I Kno the other day I tried to delete permissions on an app and after I did  In my current project at work, I had a task to add run time permissions in an android app whose code is very old and using legacy methods and frameworks/tools.

Write just a few lines of codes:

 final int requestCode=100;
     String[] per = {Manifest.permission.READ_CONTACTS};
     requestPermissions(per, requestCode);

     if (ActivityCompat.checkSelfPermission(CollectZone.this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
         // recall permission until is not permitted
     } else { 
         // write execution code here   

Control your app permissions on Android 6.0 and up, For example, an app might want permission to see your device contacts or location. You can control which permissions an app can access after the app installs on  Once again, the system just tells the user what permission groups the app needs, not the individual permissions. For example, when an app requests READ_CONTACTS the install dialog lists the Contacts group. When the user accepts, only the READ_CONTACTS permission is granted to the app.

Android Runtime Permissions Example, If I need the app to close if user denies all permissions and presses the cancel button on the message window, where and how should I do it ? Thank you so much  For a app development, android 6.0 need to get the permission from the system. Such as camera access and SD card reading permission. However, current oculus app seems not provide way to ask for permission in the VR environment. The app download from Oculus or Samsung store app will be granted with all the permissions it needs.

Requesting Runtime Permissions in Android M and N, Starting from Android Marshmallow (API 23), users will be asked for permissions while the app is running. This way, a user is able to choose  With MyPermissions, you can Scan and discover threats to your personal information and data Connect Facebook, Instagram, Twitter, Google+, Dropbox, and Yahoo to see detailed app permissions View our detailed risk analysis for each app and its permissions Clean & fix any privacy issue that threats your personal information and data.

What happens when I decline an app permission?, Starting with Marshmallow, Android has settings to control individual A new page will open that lists every permission the app is using or would want may not live near one or be ready to fully give up your old friend just yet. Android M App Permissions. Now on Android you will be able to set app permissions as they are requested and turn them off again afterwards. **** The Androidi

  • Cant understand what you are actually doing
  • @MohammedAtif Checking if permissions are granted on run time, because after Android M the permissions are not being granted during installation, but after the app is started.
  • @N.Park check my answer
  • @IntelliJAmiya Thank you. I tried your answer, but the screen still went black, this time showing only one dialog for the first permission.
  • You are not even inflating any view or adding proper actions to this special permission requesting activity. That's why you get a blank screen and app closes. Try implementing the permissions in your loginActivity itself instead of creating additional classes.
  • Kindly elobrate little bit
  • Removing android:noHistory="true" solved the problem