Skip to content

Instantly share code, notes, and snippets.

@belachkar
Created August 16, 2020 03:09
Show Gist options
  • Save belachkar/e0e6d13c80cea1666ba95263ae57bca7 to your computer and use it in GitHub Desktop.
Save belachkar/e0e6d13c80cea1666ba95263ae57bca7 to your computer and use it in GitHub Desktop.

Android permissions

Request permissions

public ContactAddressMapper(Activity activity) {
    mActivity = activity;

    // Checks whether the build SDK version is greater than that
    // of Android M; if it is then ask for permission to read
    // contacts as per the changes implemented in permission
    // requests for Android M and above.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
        && mActivity.checkSelfPermission(Manifest.permission.READ_CONTACTS)
        != PackageManager.PERMISSION_GRANTED) {
        mActivity.requestPermissions
            (new String[]{Manifest.permission.READ_CONTACTS},
             PERMISSIONS_REQUEST_READ_CONTACTS);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment