java - Why am I able to retrieve my contacts even without android.permission.READ_CONTACTS? -


i write somecode fetch contacts,but forget declare permission in androidmanifest.xml.

androidmanifest.xml code:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.ninja.mobilehelper" > <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >     <activity         android:name="com.ninja.mobilehelper.mainactivity"         android:label="@string/app_name" >         <intent-filter>             <action android:name="android.intent.action.main" />              <category android:name="android.intent.category.launcher" />         </intent-filter>     </activity> </application> </manifest> 

java code:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      uri contactsuri= contactscontract.contacts.content_uri;     string[] proj1=new string[]{contactscontract.contacts.display_name,             contactscontract.contacts.has_phone_number,             contactscontract.contacts.lookup_key};     cursor curcontacts=getcontentresolver().query(contactsuri,proj1, null, null, null);      //declare arraylist object store data present user     arraylist<string> contactslist=new arraylist<string>();     string allphoneno="";     if(curcontacts.getcount()>0){         while(curcontacts.movetonext()){             // phone numbers if exist             if(curcontacts.getint(1)>0){                 allphoneno=getallphonenumbers(curcontacts.getstring(2));             }             contactslist.add(curcontacts.getstring(0)+" , "+allphoneno);             allphoneno="";         }     }      // binding data listview     setlistadapter(new arrayadapter<string>(this,android.r.layout.simple_list_item_1,        contactslist));     listview lv=getlistview();     lv.settextfilterenabled(true);  } 

my phone moto x,android 4.4.2,uses intellijidea .

gradle builds.android build tool version '19.0.3'.

it seems required uses-permission android:name="android.permission.read_contacts" ,but works without permission! why?!

any suggestion?

addition:it's fault,i open previsously application,that declares permission.so sad, seems find bug in android - -!!

yes work if have grant uri permission in code.

 granturipermission(getpackagename(),contactscontract.contacts.content_uri, intent.flag_grant_read_uri_permission); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -