0

I have an application that having contact list and camera, Both permission that I set in Android Manifest.The application is working fine in API level 21 and below.

When I install the application in Marshmallow API level 23 from the Play Store, At the time of installing it didn't ask Permission, When I check in setting all the permission for the app deny.

For this reason when I open the application in Marshmallow the application getting crash.

Can anyone please tell me how to give the permission in Marshmallow without crash

Binil Surendran
  • 2,524
  • 6
  • 35
  • 58
  • 1
    http://developer.android.com/training/permissions/requesting.html – Madhur Feb 03 '16 at 12:24
  • can you add the code of permissions that you use? I have an application to play store that use camera and it work with marshmallow! When you download an app from Google Play, when it crash you can get the Log error. can you post the Log too? – Dario Feb 03 '16 at 12:44
  • In settings by default the camera permission is deny for that application. By manualy giving Permission to that from setting , then the app works fine – Binil Surendran Feb 03 '16 at 12:52
  • Try this it may be work http://stackoverflow.com/a/41221852/5488468 – Bipin Bharti Jan 03 '17 at 10:59

1 Answers1

2

you need to ask for permission in marshmallow, there is no other way to overcome this issue.

to check permission you can use this

checkSelfPermission(Manifest.permission.READ_CONTACTS);

If permission is given by user, it will return 0 else will return 1.

if permission is not given, ask user for permission

requestPermissions(new String[]{Manifest.permission.READ_CONTACTS},
        10);

and check whether user have granted permission or not

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
        case 10:
            if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                // Permission Granted
                Toast.makeText(MainActivity.this, "READ_CONTACTS granted", Toast.LENGTH_SHORT)
                        .show();
            } else {
                // Permission Denied
                Toast.makeText(MainActivity.this, "READ_CONTACTS Denied", Toast.LENGTH_SHORT)
                        .show();
            }
            break;
        default:
            super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
}

for more information, refer this

if you want to give support in pre-marshmallow devices also you need to use

ContextCompat.checkSelfPermission()

ActivityCompat.requestPermissions()

rest all things are same as i mentioned above.

Ravi
  • 34,851
  • 21
  • 122
  • 183