Android Permission

Spread the love

Protects Resources & Data

What are Permissions?

  • Android Protects Resources & Data with Permissions.
  • Normally Used to :
  • Limit Access to User Information (Eg: Contacts)
  • Limit Access to Cost Sensitive APIs (Eg: SMS/MMS)
  • Limit Access to System Resources (Eg: Camera )
  • Permissions are represented as Strings.
  • Declare in the Manifest.xml


Use of Permissions

App specify the permission in a special tag called “<uses-permission>” in Manifest File.

<uses-permission android:name=“android.permission.READ_CONTACTS”>



Custom Permission ( Use)

That custom permission must be declared in any app that should launch.

android:name=“” >


More Permissions

  • Component Permission
  • Service Permission
  • Broadcast Receiver Permission
  • Content Provider Permission

Send SMS

  • Check Runtime Permissions

if (ContextCompat.checkSelfPermission(this,Manifest.permission.SEND_SMS)
                != PackageManager.PERMISSION_GRANTED) {
  if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                    Manifest.permission.SEND_SMS)) {
  } else {
      new String[]{Manifest.permission.SEND_SMS}, 1);
} else{

Handle if Granted

public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
 if(requestCode==1 && grantResults.length > 0
          && grantResults[0] == PackageManager.PERMISSION_GRANTED){

Read Contacts

Open Contacts

Intent contactIntent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(contactIntent, PICK_CONTACT);


<uses-permission android:name=”android.permission.READ_CONTACTS”/>


Read & Retrieve Contact Data

protected void onActivityResult(int reqCode, int resCode, Intent intent) {
if(reqCode == PICK_CONTACT && resCode == Activity.RESULT_OK){
Uri data = intent.getData();
Cursor c = getContentResolver().query(data,
null, null, null, null);
String name =c.getString(c.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
String id =


Read & Retrieve Phone Numbers from Contact Data

Cursor numbers =
ContactsContract.CommonDataKinds.Phone.CONTACT_ID +” = “+ id, null, null);
String mobile =


  1. This is a very good tips especially to those new to blogosphere, brief and accurate information… Thanks for sharing this one. A must read article.

  2. I simply want to mention I am newbie to weblog and definitely loved this web site. Very likely I’m planning to bookmark your blog post . You really come with impressive article content. Cheers for sharing your webpage.

Leave a Reply

Your email address will not be published.