We all know how to add a new contact to our android devices without programming right.
OK that’s a normal man’s use.
But what from a programmer’s view.
OK that’s a normal man’s use.
But what from a programmer’s view.
import
java.util.ArrayList;
import
android.app.Activity;
import
android.content.ContentProviderOperation;
import
android.content.ContentValues;
import
android.net.Uri;
import
android.os.Bundle;
import
android.provider.ContactsContract;
import
android.provider.Contacts.People;
import
android.provider.ContactsContract.CommonDataKinds.Phone;
import
android.widget.Toast;
public
class
AddContactDemo
extends
Activity {
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
addContact(
"Hardik"
,
"1234567890"
);
addContact(
"Alex"
,
"5656215521"
);
addContact(
"Kenedy"
,
"4545454545"
);
addContact(
"Peter"
,
"9632587410"
);
addContact(
"John"
,
"4561237890"
);
}
private
void
addContact(String name, String phone) {
ContentValues values =
new
ContentValues();
values.put(People.NUMBER, phone);
values.put(People.TYPE, Phone.TYPE_CUSTOM);
values.put(People.LABEL, name);
values.put(People.NAME, name);
Uri dataUri = getContentResolver().insert(People.CONTENT_URI, values);
Uri updateUri = Uri.withAppendedPath(dataUri, People.Phones.CONTENT_DIRECTORY);
values.clear();
values.put(People.Phones.TYPE, People.TYPE_MOBILE);
values.put(People.NUMBER, phone);
updateUri = getContentResolver().insert(updateUri, values);
}
}
Your posts are really inspiring and useful. I think you deserve better attention on Google search
ReplyDeleterankings.
click Here
Thanks for according to critical information including all of us. It was surprisingly soft to work. I absolutely like your opinions.
ReplyDeleteMust be watch this review
I really liked reading your post! Very high quality content and useful information similar to my post on places to visit to With such a valuable website I believe you deserve to be ranking even higher in the search engines.
ReplyDeleteclick Here