Is possible to start default people/contact activity and pass structured data like
separated first name and last name, phone type, city, postal code and similar data.
I use following similar code:
Intent addContactIntent = new Intent(Intent.ACTION_INSERT);
addContactIntent.setType(ContactsContract.Contacts.CONTENT_TYPE);
addContactIntent.putExtra(ContactsContract.Intents.Insert.POSTAL, "abc 2343");
startActivity(addContactIntent );
This works fine but I can't specify which is for example postal code, and what is city or place.
I found samples like this here but I cant start add new contact intent before, so user can't edit something before he saves contact. Code immediately saves the contact without user interaction.
Any help would be appreciable.
As for your information you can use ContactsContract.Intents.Insert.DATA ,which is designed to insert multiple data items.Like city,state etc for the address field.But the real problem is it in not available prior to API 11.
Here is how its work.
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
//Email
ContentValues row1 = new ContentValues();
row1.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE);
row1.put(Email.ADDRESS, "ADDRESSme");
data.add(row1);
//Website
ContentValues row2 = new ContentValues();
row2.put(Data.MIMETYPE, Website.CONTENT_ITEM_TYPE);
row2.put(Website.URL, "URLme");
data.add(row2);
//Address
ContentValues row4 = new ContentValues();
row4.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
row4.put(StructuredPostal.CITY, "CityMe");//Pre populating city
row4.put(StructuredPostal.COUNTRY, "COUNTRYme");//Pre populating country
row4.put(StructuredPostal.STREET, "STREETme");////Pre populating street
row4.put(StructuredPostal.POSTCODE, "POSTCODEme");//
data.add(row4);
Intent i = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
i.putParcelableArrayListExtra(Insert.DATA, data);
Related
Most developers complain about the difficult API when trying to create an android system contact.
I want to create one with an intent, that is the contact app opens and has filled the appropiate fields from the passed intent data.
I know that I can set the first and the lastname just like this:
intent.putExtra(ContactsContract.Intents.Insert.NAME, "Firstname Lastname");
The builtin contactapp splits the string automatically and sets the first words to the GIVEN_NAME field and the last word corresponds to the FAMILY_NAME field.
But adding the prefix and suffix words into that string dont fill the PREFIX, SUFFIX fields.
This also will have no effect, just as depicted here:
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues name = new ContentValues();
name.put(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE);
name.put(ContactsContract.CommonDataKinds.StructuredName.PREFIX, "Sir");
name.put(ContactsContract.CommonDataKinds.StructuredName.GIVEN_NAME, "John");
name.put(ContactsContract.CommonDataKinds.StructuredName.FAMILY_NAME, "Doe");
data.add(name);
intent.putExtra(ContactsContract.Intents.Insert.DATA, data);
startActivity(intent);
So how do I transfer the prefixes and suffixes to the contacts app via an intent?
The thing is, there are no official example codes to work with the contactsContract API, its just so frustrating.
The way you build ArrayList<ContentValues> data seems ok, but then according to the docs it should be added to an intent using:
Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
intent.putParcelableArrayListExtra(Insert.DATA, data);
startActivity(intent);
So the full code would be:
ContentValues name = new ContentValues();
name.put(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE);
name.put(StructuredName.PREFIX, "Sir");
name.put(StructuredName.GIVEN_NAME, "John");
name.put(StructuredName.FAMILY_NAME, "Doe");
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
data.add(name);
Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
intent.putParcelableArrayListExtra(Insert.DATA, data);
startActivity(intent);
I am trying to do this by writing this code
ContentValues values = new ContentValues();
values.put(Sms.TYPE, Sms.MESSAGE_TYPE_SENT);
context.getContentResolver().update(Uri.parse("content://sms"), values, Sms.THREAD_ID+"=? AND "+Sms._ID+"=?", new String[]{thread_id,_id);
but no luck! this is not working.
so, help would be appericiated.
I am using Intent.ACTION_INSERT_OR_EDIT for inserting/editing contact to mobile phone.
However, I put a ContactsContract.Intents.Insert.NAME to bundle for case when user want to insert a new contact. But the name is inserted also when user choose edit contact (the old name is rewrited) ... is there some FLAG or something how to prevent this behavior ?
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.NAME,
u.getName());
intent.putExtra(INTENT_KEY_FINISH_ACTIVITY_ON_SAVE_COMPLETED,
true);
startActivityForResult(intent, ADD_CONTACT);
I want to pass Street, City, State of Address field to create new contact or update existing contact activity.
ArrayList<ContentValues> data = new ArrayList<ContentValues>();
ContentValues row1 = new ContentValues();
row1.put(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE);
row1.put(StructuredPostal.CITY, "mCity");
row1.put(StructuredPostal.COUNTRY, "mCountry");
row1.put(StructuredPostal.STREET, "mStreet");
row1.put(StructuredPostal.POSTCODE, "mPostCode");
data.add(row1);
Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, "9XXXXXXXXX");
intent.putExtra(ContactsContract.Intents.Insert.PHONE_TYPE, ContactsContract.CommonDataKinds.Phone.TYPE_WORK);
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, "mCompanyName");
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, data);
startActivity(intent);
But here address is not visible in edit contact widow. Also I don't want to add contact directly using ContentProviderOperation. I want to show first edit contact window with above pre-filled fields.
I'm trying to open the System SMS application with a sms body that is taken from a database.
I'm using Cursor to retrieve titles and messages from a SQLite database. I have a smsButton which will be clicked. When clicked, it will create the sms intent.
My problem is with the body of the message. I want the body to be the msg_content which is retrieved from the database. I tried to have a reference to it but I believe I failed.
here is my last attempt, trying to have a TextView that will take the id of the msg_content layout :
//First: DataBase Retrieving :
//fetch a msg from table `t` with id `id`
Cursor cursor = myDbHelper.fetchMessage(t, id);
String[] columns = {cursor.getColumnName(1), cursor.getColumnName(2)};
int[] columnsLayouts = {R.id.title, R.id.msg_content}; //the columns styles
ca = new SimpleCursorAdapter(this.getBaseContext(), R.layout.msg_items_layout, cursor,columns , columnsLayouts);
lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(ca);
//Here is MY PROBLEM :
TextView msgText = (TextView) findViewById(R.id.msg_content); //same Id as the msg_content column above
smsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String uri= "smsto:";
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse(uri));
intent.putExtra("sms_body", msgText.getText());
intent.putExtra("compose_mode", true);
startActivity(intent);
}
});
Any way to reference the string of the content ?
You are calling findViewById() on an activity... to get data out of database?
You should be using your Cursor to get at your information.
Since you did not bother to provide the actual source code (just a couple of dis-contiguous snippets, AFAICT), it is difficult to give you concrete advice. Taking a random stab at an answer, I would delete smsButton, and instead listen for ListView item clicks (e.g., onListItemClick() if you are implementing a ListActivity), then use the supplied position to move to the right spot in the Cursor and read out the data.