1. sylsau's Avatar

    I create that thread to offer you a new tutorial aiming to learn how to manage System Permissions in Android Marshmallow. You can discover the tutorial in video also :

    Manage System Permissions on Android 6 Marshmallow

    Beginning in Android 6 Marshmallow, users grand permissions to apps while the app is running, not when they install the app. This approach gives the user more control over the app's functionality. Thus, he can choose to give the access to read contacts but not to the device location. Furthermore, users can revoke the permissions at any time, by going to the app's Settings screen.

    Note that system permissions are divided into two categories : normal and dangerous. Normal permissions are granted automatically. For dangerous permissions, the user has to give approval to your application at runtime. So, developers must manage permissions at runtime before using some dangerous features.

    To manage permissions inside an application, we're going to imagine we want to read contacts. This feature will use the READ_CONTACTS permission that is marked as dangerous. So, the first step is to check for READ_CONTACTS permission. If the permission has already been granted, you can use the feature that read contacts. If not, you have to request for permissions with a custom request code that will be named MY_PERMISSIONS_REQUEST_READ_CONTACTS in our example.

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS)
          != PackageManager.PERMISSION_GRANTED) {
           new String[] { Manifest.permission.READ_CONTACTS },
    } else {
    Note that when your application requests for permissions, the system shows a standard dialog box to user that cannot be customized. Now, you need to handle the permissions request response by overriding the onRequestPermissionsResult method :

    public void onRequestPermissionsResult(int requestCode,
             @NonNull String[] permissions, @NonNull int[] grantResults) {
      switch (requestCode) {
          if (grantResults.length > 0
             && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
          } else {
                    Manifest.permission.READ_CONTACTS)) {
                new AlertDialog.Builder(this).
                    setTitle("Read Contacts permission").
                    setMessage("You need to grant read contacts permission to use read" +
                               " contacts feature. Retry and grant it !").show();
             } else {
                new AlertDialog.Builder(this).
                    setTitle("Read Contacts permission denied").
                    setMessage("You denied read contacts permission." +
                               " So, the feature will be disabled. To enable it" +
                               ", go on settings and " +
                               "grant read contacts for the application").show();
    Like you can see, managing permissions in your Android application is not really hard.

    Don't hesitate to give me your feedbacks or ideas for new tutorials.


    B. Diddy likes this.
    09-10-2016 02:26 AM
  2. B. Diddy's Avatar
    Awesome post, thanks Sylvain!
    09-11-2016 02:43 AM

Similar Threads

  1. Moto z in RĂºssia
    By rjardim in forum Moto Z
    Replies: 1
    Last Post: 09-10-2016, 08:35 AM
  2. Apps in Application Manager...Can't Find on Phone
    By cmcaro70 in forum Ask a Question
    Replies: 1
    Last Post: 09-10-2016, 05:32 AM
  3. Replies: 1
    Last Post: 09-10-2016, 02:37 AM
  4. My android tab not charging.
    By AC Question in forum Ask a Question
    Replies: 0
    Last Post: 09-10-2016, 02:03 AM
  5. Download manager for one-click-hoster with sd card support
    By AC Question in forum Ask a Question
    Replies: 0
    Last Post: 09-09-2016, 10:07 PM

Tags for this Thread