android - Facing java.lang.RuntimeException: Failure delivering result ResultInfo on getActivity().getContentResolver().query() -
i using implicit intent select contact , call it, facing following exception, happens when invoking getactivity().getcontactresolver().query()
. separately checked invocation individually , ensure none of them null.
here code recover info selected contact:
public void onactivityresult(int requestcode, int resultcode, intent data) { if (resultcode != activity.result_ok) return; else if (requestcode == request_date_code) { gregoriancalendar date = (gregoriancalendar) data.getserializableextra(datepickerfragment.extera_date); mcrime.setdate(date); updatedate(); } else if (requestcode == request_contact && data != null) { uri contacturi = data.getdata(); string[] queryfields = new string[]{contactscontract.contacts.display_name, contactscontract.contacts._id}; cursor c = getactivity().getcontentresolver().query(contacturi, queryfields, null, null, null); try { if (c.getcount() == 0) { return; } c.movetofirst(); string suspect = c.getstring(0); id = c.getint(1); mcrime.setsuspect(suspect); msuspectbutton.settext(suspect); //mcallsuspectbutton.setenabled(true); } { c.close(); } } /* retriving phone number */ super.onactivityresult(requestcode, resultcode, data); }
the code retrieve phone number selected contact:
mcallsuspectbutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { uri contenturi = contactscontract.commondatakinds.phone.content_uri; string[] fields = {contactscontract.commondatakinds.phone.number}; //string whereclause = contactscontract.commondatakinds.phone._id + " = ?"; string whereclause = contactscontract.commondatakinds.phone.contact_id + " = ?"; string[] args = {integer.tostring(id)}; cursor cursor = getactivity().getcontentresolver().query(contenturi, fields, whereclause, args, null); try { if (cursor.getcount() == 0) { return; } cursor.movetofirst(); string number = cursor.getstring(0); uri phonenumber = uri.parse("tel:" + number); intent intent = new intent(intent.action_dial, phonenumber); startactivity(intent); } { cursor.close(); } } });
and exception caused getactivity().getcontactresolver().query()
12 07:04:40.104 22246-22246/com.example.yahya.criminalintent e/androidruntime: fatal exception: main process: com.example.yahya.criminalintent, pid: 22246 java.lang.runtimeexception: failure delivering result resultinfo{who=null, request=65537, result=-1, data=intent { dat=content://com.android.contacts/contacts/lookup/1394i351ae9650f3502e4.1394i6e48faf708f8d3e8.3789r2291-4d2943295b3b2943/2331 flg=0x1 }} activity {com.example.yahya.criminalintent/com.example.yahya.criminalintent.crimepageractivity}: java.lang.securityexception: permission denial: reading com.android.providers.contacts.semccontactsprovider2 uri content://com.android.contacts/data/phones pid=22246, uid=10358 requires android.permission.read_contacts, or granturipermission() @ android.app.activitythread.deliverresults(activitythread.java:4185) @ android.app.activitythread.handlesendresult(activitythread.java:4228) @ android.app.activitythread.-wrap20(activitythread.java) @ android.app.activitythread$h.handlemessage(activitythread.java:1564) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:241) @ android.app.activitythread.main(activitythread.java:6274) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:886) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:776) caused by: java.lang.securityexception: permission denial: reading com.android.providers.contacts.semccontactsprovider2 uri content://com.android.contacts/data/phones pid=22246, uid=10358 requires android.permission.read_contacts, or granturipermission() @ android.os.parcel.readexception(parcel.java:1689) @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:183) @ android.database.databaseutils.readexceptionfromparcel(databaseutils.java:135) @ android.content.contentproviderproxy.query(contentprovidernative.java:427) @ android.content.contentresolver.query(contentresolver.java:534) @ android.content.contentresolver.query(contentresolver.java:475) @ com.example.yahya.criminalintent.crimefragment.onactivityresult(crimefragment.java:355) @ android.support.v4.app.fragmentactivity.onactivityresult(fragmentactivity.java:164) @ android.app.activity.dispatchactivityresult(activity.java:6973) @ android.app.activitythread.deliverresults(activitythread.java:4181) @ android.app.activitythread.handlesendresult(activitythread.java:4228) @ android.app.activitythread.-wrap20(activitythread.java) @ android.app.activitythread$h.handlemessage(activitythread.java:1564) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:241) @ android.app.activitythread.main(activitythread.java:6274) @ java.lang.reflect.method.invoke(native method) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:886) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:776)
you need add below permission in manifest file
<uses-permission android:name="android.permission.read_contacts" />
Comments
Post a Comment