android - Read SIM card contacts -
android - Read SIM card contacts -
i developping android application, , want read or sim card contacts button click. help me ?
my button xml code :
<button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@+id/third" android:layout_below="@+id/third" android:layout_margintop="30dp" android:text="read contact" android:onclick="contactsaccess"/>
i need java code used within methode (contactsaccess).
public class mainactivity extends actionbaractivity implements onclicklistener { button sim_btn; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.your_view); sim_btn = (button)findviewbyid(r.id.button1); sim_btn.setonclicklistener(this); getallsimnumber(); } getallsimnumber(){ seek { string clssimphonename = null; string clssimphoneno = null; uri simuri = uri.parse("content://icc/adn"); cursor cursorsim = this.getcontentresolver().query(simuri,null,null,null,null); log.i("phonecontact", "total: "+cursorsim.getcount()); while (cursorsim.movetonext()) { clssimphonename =cursorsim.getstring(cursorsim.getcolumnindex("name")); clssimphoneno = cursorsim.getstring(cursorsim.getcolumnindex("number")); clssimphoneno.replaceall("\\d",""); clssimphoneno.replaceall("&", ""); clssimphonename=clssimphonename.replace("|",""); log.i("phonecontact", "name: "+clssimphonename+" phone: "+clssimphoneno); } } catch(exception e) { e.printstacktrace(); } }
android sdk sim-card
Comments
Post a Comment