Skip to content

Instantly share code, notes, and snippets.

@chap19150
Created June 15, 2015 02:50
Show Gist options
  • Select an option

  • Save chap19150/0b0df56c3a347409056d to your computer and use it in GitHub Desktop.

Select an option

Save chap19150/0b0df56c3a347409056d to your computer and use it in GitHub Desktop.

Revisions

  1. chap19150 created this gist Jun 15, 2015.
    30 changes: 30 additions & 0 deletions android_m_permissions
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    private static final int PERMISSIONS_REQUEST_READ_CONTACTS = 1;
    private static String[] PERMISSIONS_CONTACT = {Manifest.permission.READ_CONTACTS}

    if (checkSelfPermission(PERMISSIONS_CONTACT)) {
    Log.i(TAG,
    "Contact permissions have already been granted. Displaying contact details.");
    } else {
    Log.i(TAG, "Contact permissions has NOT been granted. Requesting permission.");
    requestPermissions(PERMISSIONS_CONTACT, PERMISSIONS_REQUEST_READ_CONTACTS);
    }


    @Override
    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    switch (requestCode) {
    case PERMISSIONS_REQUEST_READ_CONTACTS: {
    if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
    // permission was granted, yay! do the
    // calendar task you need to do.
    Log.d(TAG, "permission granted");
    } else {
    // permission denied, boo! Disable the
    // functionality that depends on this permission.
    Log.d(TAG, "permission denied");
    }
    return;
    }
    }
    }