database - How to get Contacts in a Table in Android using SQLite? -


i want contacts stored on phone table created in sqlite db. columns show different fields e.g name, phone number, email etc , each row shows different contact. how achieve this?

use androids content provider contacts data cursor , iterate cursor rows , save data sqlite

first add permission:-

<uses-permission android:name="android.permission.read_contacts" > </uses-permission> 

then in java class:-

cursor phones = getcontentresolver().query(contactscontract.commondatakinds.phone.content_uri, null,null,null, null); while (phones.movetonext()) {   string name=phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.display_name));   string phonenumber = phones.getstring(phones.getcolumnindex(contactscontract.commondatakinds.phone.number));  } phones.close(); 

in while loop add sqlite data base


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -