android - Unable to add contact in my device -


I have tried the following code to add new contacts in my contacts that is not working in my device. But it's working fine with the same code emulator. I am using the Samsung Galaxy Fit GT-5656.

Code Style - 1

  Content Value Value = New Content Value (); Values.put (people. NAME, "test contact"); Uri Uri = getContentResolver (). Enter (people. CONTENT_URI, value); Uri Phone URI = Faucet; Uri Email Yuri = Null; PhoneURI = Uri Expected Word (Yuri, Peoples. Phones. CONTENT_DIRECTORY); Values.clear (); Values.put (People. Phones, People. Phones. TYPE_MOBILE); Values.put (People.Phones.NUMBER, "0123456789"); GetContentResolver () Insert (phone Yuri, value); Email Yuri = Uri. Along with expected terms (Yuri, People's contact method. CONTENT_DIRECTORY); Values.clear (); Values.put (People contact. Method KIND, contact. KIND_EMAIL); Values.put (People.ContactMethods.DATA, "test@test.com"); Values.put (People contact method, people, people, contact methods, TEP_HOME); GetContentResolver () Insert (Email, Yuri, Value);   

Code style - 2

  intent to intent = new intent (contact. Intent. Indent, contact, people, CONTRAINSURI); Intent.putExtra (ContactContact.intent.Interat.N.I., "Test Contact"); Intent.putExtra (ContactsContract.Intents.Insert.PHONE, "0123456789"); Intent.putExtra (ContactsContract.Intents.Insert.EMAIL, "test@test.com"); StartActivity;   

I tried it in both ways but I can not add it to my device. Please help me solve ..

Thank you.

Try this link

or use this code.

  ArrayList & lt; ContentProviderOperation & gt; Ops = new arreelist & lt; Content provider operation & gt; (); Int rawContactInsertIndex = ops.size (); Ops.add (ContentProviderOperation.newInsert (RawContacts.CONTENT_URI) .withValue (RawContacts.ACCOUNT_TYPE, blank) .withValue (RawContacts.ACCOUNT_NAME, blank) .build ()); Ops.add (ContentProviderOperation.newInsert (contactContract.Data.CONTENT_URI) .withValueBackReference (ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex) .withValue (Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE) .withValue (Phone No. NUMBER, "9X-XXXXXXXXX") Creation ()); Ops.add (ContentProviderOperation.newInsert (Data.CONTENT_URI) .withValueBackReference (Data.RAW_CONTACT_ID, rawContactInsertIndex) .withValue (Data.MIMETYPE, Structured Names. CONTENT_ITEM_TYPE) .withValue (Structured.name.card, "Mike Sullivan") .build () ); ContentProviderResult [] res = getContentResolver () ApplyBatch (ContactsContract.AUTHORITY, Ops);    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -