I am using update method to update my contact but when i go to my contact list to see the udpated number it shows me the previous number store , whats wrong with code can any sort it , how to udpate the contacts
ContentValues newPhone = new ContentValues();
updateUri=Uri.withAppendedPath(uri, People.Phones.CONTENT_DIRECTORY);
newPhone.put(People.Phones.TYPE, People.TYPE_MOBILE);
newPhone.put(People.NUMBER, phone);
//newPhone.clear();
Log.v("--- PHONE NUMBER ","---VALUE ---- "+phone);
//getContentResolver().update(updateUri, newPhone, null,null);
getContentResolver().insert(updateUri, newPhone);
Toast.makeText(NativeContentProvider.this, "Updated the phone number to: " + phone, Toast.LENGTH_SHORT).show();
Log.i(getClass().getSimpleName(), "Updated the phone number");
add permission to add/edit contact in menifest .
if already done , tell more about error you are facing . error log result will be very helpful to understand
Related
I'm using ContactsContract to insert RawContacts in my app. The following code (and showing the inserted contact in the contact app) works on all devices, but not on Sony Xperia (Android 4.4.4).
ContentValues p=new ContentValues();
p.put(ContactsContract.RawContacts.ACCOUNT_TYPE, getActivity().getPackageName());
p.put(ContactsContract.RawContacts.ACCOUNT_NAME,
DataHelper.getAppName(getActivity()));
Uri rowcontact = null;
long rawcontactid = 0;
try {
rowcontact = getActivity().getContentResolver().insert(ContactsContract.RawContacts.CONTENT_URI, p);
rawcontactid = ContentUris.parseId(rowcontact);
Log.d(DEBUG_KEY, "CONTACT ADDED: " + rawcontactid);
}catch(Exception e){
Log.d(DEBUG_KEY, "CONTACT ADDED FAILED 1: " + e.getMessage());
return "";
}
On the Sony Xperia Device there is no error or exception. The console display the correct CONTACT-ADDED-ID. But in the android contact app the newly inserted (Raw)-Contact is not showing. I have enabled all groups, etc. in the filter-settings in the contact app.
Ok. Problem is solved. On Sony Xperia Devices you must
(1) Specify an existing (google) account
p.put(ContactsContract.RawContacts.ACCOUNT_TYPE, "com.google");
p.put(ContactsContract.RawContacts.ACCOUNT_NAME, "google_account_username_on_device");
or (2) don't specify any account type details
//p.put(ContactsContract.RawContacts.ACCOUNT_TYPE, "com.google");
//p.put(ContactsContract.RawContacts.ACCOUNT_NAME, "google_account_username_on_device");
On other devices like Motorola oder Google Nexus you can specify a non existing, custom Account, like:
p.put(ContactsContract.RawContacts.ACCOUNT_TYPE, "my.app.name");
p.put(ContactsContract.RawContacts.ACCOUNT_NAME, "APP NAME");
Looking for some help regarding querying in different verions of Android. I have the following code that returns a cursor of bookmarks. I am trying to filter the browser to return only urls that are actual bookmarks, not just browser history. It works on version 3.1 but on my new Nexus 7, it will not filter by bookmark, but instead returns all browser history in the cursor. Any insight is much appreciated. I think I have run into issues with filtering and content resolver query's not paying attention to selection parameters but can't seem to find any info. Thanks.
String[] mColumnStrings =
{
Browser.BookmarkColumns.TITLE,
Browser.BookmarkColumns.URL,
Browser.BookmarkColumns._ID,
Browser.BookmarkColumns.BOOKMARK
};
try{
bookmarksCursor = getActivity().getContentResolver().query(Browser.BOOKMARKS_URI, mColumnStrings, Browser.BookmarkColumns.BOOKMARK+ " = 1 ", null , Browser.BookmarkColumns.URL + " ASC");
getActivity().startManagingCursor(bookmarksCursor);
return bookmarksCursor;
Its working fine for me...I tested it on AVD...actually Android 4.1 already have some default bookmarks...print the Browser.BookmarkColumns.BOOKMARK as well to verify weather the results are bookmarked or not...
You can use this method specifically for your to varify...
private void varify(Cursor bookmarksCursor) {
bookmarksCursor.moveToFirst();
while(bookmarksCursor.moveToNext()) {
Log.v("title", bookmarksCursor.getString(0));
Log.v("url", bookmarksCursor.getString(1));
Log.v("id", bookmarksCursor.getString(2));
Log.v("bookmark", bookmarksCursor.getString(3));
}
}
Hope this works...
If you decide that this answers your question, please mark it as "accepted". This will raise both your and my reputation score.
I am developing app which add contact info to android contact list .to How to add postal address to contacts in android programmatically ?
It's been a while that this has been asked but maybe someone else is still interested in it. How to add a contact with address info:
import static android.provider.ContactsContract.Data;
import static android.provider.ContactsContract.Intents.Insert;
private void createContactIntent() {
Intent contactIntent = new Intent(ContactsContract.Intents.Insert.ACTION, ContactsContract.Contacts.CONTENT_URI);
contactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
contactIntent.putExtra(Insert.NAME, "Sergio Mendes");
contactIntent.putExtra(Insert.COMPANY, "Company One");
contactIntent.putExtra(Insert.POSTAL, "Street 1, 9999 City, Country");
contactIntent.putExtra(Data.IS_SUPER_PRIMARY, 1);
startActivity(contactIntent);
}
Note that some devices like Samsung S5 / A5 will put the whole address into the "street" field. If you have any optimizations for this let me know.
Postal address are stored like all the other info in the DATA table with a
MIMEtype == ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE
Please google ContactsContract.CommonDataKinds.StructuredPostalto find all the info.
If you need to know how to edit a contact in general I would suggest you to have a look to the SampleSyncAdapter in the Android SDK. It is a sync adapter so you don't need to study everything but updateContact in ContactManager is a good point to start with.
iam just practicing with phone gap for android app. I found a piece of code in docs.phonegap.com, regarding adding contacts
function onDeviceReady()
{
alert('onDeviceReady: PhoneGap1');
var myContact = navigator.contacts.create({"displayName": "Test User"});
alert('onDeviceReady: PhoneGap2');
myContact.gender = "male";
console.log("The contact, " + myContact.displayName + ", is of the " + myContact.gender + " gender");
}
When i run this i am getting only the alert box and the name is not added in my contacts. How to add the contacts....
Please tell me how to add data and open the device default contacts...
Simon Mac Donald has written a great blog post on contacts with PhoneGap and Android.
http://simonmacdonald.blogspot.com/2011/09/saving-contacts-with-phonegap-android.html
It should help you out as there are a few steps to it.
The quick answer for those of you searching, is that you have to call
myContact.save()
in order to persist the contact that you just created.
In my app i'm trying to create a Contact by calling the standard Create/Edit contact Activity.
I've found how to make it work but not exactly the way I like.
For now I manage to call the standard create contact activity with the following intent extra:
Intent i = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, Uri.parse(String.format("tel: %s", data.getPhone())));
i.addCategory(Intent.CATEGORY_DEFAULT);
i.putExtra(ContactsContract.Intents.EXTRA_FORCE_CREATE, true);
i.putExtra(ContactsContract.Intents.Insert.NAME, data.getName());
i.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.PHONE, org.getPhone());
i.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.POSTAL, org.getAddress() + " " + org.getZipCode());
i.putExtra(ContactsContract.Intents.Insert.EMAIL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.Intents.Insert.EMAIL, org.getEmail());
startActivity(i);
All the data is filled properly except the address field as you can see in the following picture: http://img689.imageshack.us/img689/1073/capturevvm.png
I'd like to specify each part of the address in the separate field. Is there a way to do it with an Intent?
I tried this, but it did not work.
i.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
i.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.STREET, "toto");
i.putExtra(ContactsContract.CommonDataKinds.StructuredPostal.CITY, "paris");
Any idea?
contactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "2 rue de Romme, 75000 Paris");
contactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_WORK);
You can add the contact using the technique at New contacts created using ContactsContract do not appear in Contacts app
Then show it using your technique.