Tuesday, 23 May 2017

Android 6.0(Marshmallow) Runtime Permissions


 Android 6.0 Runtime permissions :

1) For read phone state

Request Permission :
 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, 1);

Check Permission :
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_PHONE_STATE)
                        != PackageManager.PERMISSION_GRANTED) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_PHONE_STATE}, 1);

                } else {

                  //call your method
                }


2) For Read and Write External storage

Request Permission :
 ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);

 ActivityCompat.requestPermissions((this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE},READ_STORAGE);

Check Permission :
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
 != PackageManager.REQUEST_CODE) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_CODE);

                } else {

                  //call your method
                }



if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_EXTERNAL_STORAGE)
 != PackageManager.READ_STORAGE) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_EXTERNAL_STORAGE}, READ_STORAGE);

                } else {

                  //call your method
                }


3) For manage Phone Calls

Request Permission :
 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, REQUEST_CODE);

Check Permission 
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CALL_PHONE)
 != PackageManager.REQUEST_CODE) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CALL_PHONE}, REQUEST_CODE);

                } else {

                  //call your method
                }

4) For GPS permission

Request Permission :
 ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);

Check Permission 
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
 != PackageManager.REQUEST_LOCATION) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_LOCATION);

                } else {

                  //call your method
                }

5) For Camera permission

Request Permission :
 ActivityCompat.requestPermissions(this, new String[] {android.Manifest.permission.CAMERA}, requestCode);

Check Permission 
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.CAMERA)
 != PackageManager.requestCode) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.CAMERA}, requestCode);

                } else {

                  //call your method
                }

6) For Send SMS permission

Request Permission :
  ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.SEND_SMS},  requestCode);

Check Permission 
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.SEND_SMS)
 != PackageManager.requestCode) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.SEND_SMS}, requestCode);

                } else {

                  //call your method
                }


7) For Received SMS

Request Permission :
ActivityCompat.requestPermissions(this, new String[] 
{android.Manifest.permission.RECEIVE_SMS}, PERMISSION_REQUEST_CODE);


Check Permission 
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.RECEIVE_SMS)
 != PackageManager.PERMISSION_REQUEST_CODE) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.RECEIVE_SMS}, PERMISSION_REQUEST_CODE);

                } else {

                  //call your method
                }

8) For Read Contacts permission

Request Permission :
 ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_CONTACTS},REQUEST_READ_CONTACT);

Check Permission 
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.READ_CONTACTS)
 != PackageManager.REQUEST_READ_CONTACT) {

                    ActivityCompat.requestPermissions(this, new String[]{android.Manifest.permission.READ_CONTACTS}, REQUEST_READ_CONTACT);

                } else {

                  //call your method
                }

Alarm Manager Example in Android