Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. <uses-permission android:name="android.permission.READ_CONTACTS" >
  2. </uses-permission>
  3.  
  4. Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
  5. while (phones.moveToNext())
  6. {
  7. String name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
  8. String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
  9.  
  10. }
  11. phones.close();
  12.  
  13. public class DatabaseHelper extends SQLiteOpenHelper {
  14.  
  15. public static final String DATABASE_NAME = "EventBoard.db";
  16. public static final String EVENTS_TABLE = "Events";
  17. public static final String GUESTS_TABLE = "Guests";
  18.  
  19. public DatabaseHelper(Context context) {
  20. super(context, DATABASE_NAME, null, 1);
  21. }
  22.  
  23. @Override
  24. public void onCreate(SQLiteDatabase db) {
  25. db.execSQL("create table " + EVENTS_TABLE + "( _id INTEGER PRIMARY KEY AUTOINCREMENT,Name TEXT,Time TEXT,Date TEXT,Venue TEXT,Contact TEXT,Description TEXT);");
  26. db.execSQL("create table " + GUESTS_TABLE + "(Name TEXT,Phone TEXT,Email TEXT);");
  27. createGuestsTable(this);
  28. }
  29.  
  30. public void createGuestsTable(Context context){
  31. Cursor phones = context.getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,null,null,null);
  32. while(phones.moveToNext()){
  33. String name = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
  34. String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
  35. String email = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Email.ADDRESS));
  36. SQLiteDatabase db = this.getWritableDatabase();
  37. ContentValues contentValues = new ContentValues();
  38. contentValues.put("Name", name);
  39. contentValues.put("Phone", phoneNumber);
  40. contentValues.put("Email", email);
  41. db.insert(GUESTS_TABLE,null,contentValues);
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement