-1

I have added all the permissions in the manifest file. In Lollipop and all the application will ask for permissions during install the app, but when the application is installed in marshmallow the permission is not asking.

Manifest Permissions are

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<!-- My Location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.CALL_PHONE" />
Hitesh Sahu
  • 38,157
  • 14
  • 182
  • 142
Maria
  • 1
  • 2
  • so are you getting any error when you run the app in the marshmallow device ? – Sagar Nayak Jun 16 '16 at 09:36
  • No i am not getting any error . But the first activity is splash screen and then the google map the map is not getting populated. None of the function is working.The permissions are need to added from the settings>app . I need to ask when install or run the application – Maria Jun 16 '16 at 10:09

3 Answers3

2

May be want to use third party library to simplify permission process, these libraries can help to you.

PermissionsDispatcher

Dexter

RxPermissions

okarakose
  • 3,157
  • 5
  • 23
  • 40
0

First declare :

// Assume thisActivity is the current activity

    int permissionCheck = ContextCompat.checkSelfPermission(thisActivity,
            Manifest.permission.WRITE_CALENDAR);

Request the permissions you need :

// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
                Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {

    // Should we show an explanation?
    if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
            Manifest.permission.READ_CONTACTS)) {

        // Show an expanation to the user *asynchronously* -- don't block
        // this thread waiting for the user's response! After the user
        // sees the explanation, try again to request the permission.

    } else {

        // No explanation needed, we can request the permission.

        ActivityCompat.requestPermissions(thisActivity,
                new String[]{Manifest.permission.READ_CONTACTS},
                MY_PERMISSIONS_REQUEST_READ_CONTACTS);

        // MY_PERMISSIONS_REQUEST_READ_CONTACTS is an
        // app-defined int constant. The callback method gets the
        // result of the request.
    }
}

Handle the permissions request response:

@Override
public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
    switch (requestCode) {
        case MY_PERMISSIONS_REQUEST_READ_CONTACTS: {
            // If request is cancelled, the result arrays are empty.
            if (grantResults.length > 0
                && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

                // permission was granted, yay! Do the
                // contacts-related task you need to do.

            } else {

                // permission denied, boo! Disable the
                // functionality that depends on this permission.
            }
            return;
        }

        // other 'case' lines to check for other
        // permissions this app might request
    }
}
Bhumit
  • 238
  • 3
  • 13
0

Firstly, you need to classify all these permissions. On Android M version, they are mainly divided to Normal permissions(Like ACCESS_NETWORK_STATE in your Manifest file) and Dangerous permissions(like ACCESS_FINE_LOCATION). For Normal ones you don't have to request them which are granted automatically without a user reminder on installation any more. What you only need to do is just adding them in Manifest!

However, Dangerous permissions are more complicated to handle. On app starts up or runs to corresponding feature, you MUST firstly check whether the permissions have been acquired by Context.checkSelfPermission(String permission). Call Context.requestPermissions(String[] permissions, int requestCode) to request by system dialog and get result onRequestPermissionsResult().

Good news is you can request a bunch of permissions by one API as app launches. Furthermore, Dangerous permissions are managed in several groups. For example, you only need to request for ACCESS_FINE_LOCATION and get ACCESS_COARSE_LOCATION permission as well.

Korneel
  • 1,447
  • 15
  • 40
shaomin
  • 1
  • 1