Android Intents.SHOW_OR_CREATE_CONTACT always show only the Uri string - android

I need to show/interact with a new contact before create it, and I need a simple way to add it to the phone contacts.
this is the code I use:
String contactPhone = "33333333";
Uri contactUri = Uri.parse(String.format("tel: %s", contactPhone));
Intent addContactIntent = new Intent(
ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, contactUri);
addContactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "FirstName" );
addContactIntent.putExtra(ContactsContract.Intents.Insert.COMPANY,"CompanyName");
addContactIntent.putExtra(ContactsContract.Intents.Insert.PHONE,contactPhone);
addContactIntent.putExtra(ContactsContract.Intents.Insert.EMAIL,"contact#email.com");
startActivity(addContactIntent);
and this is the result. The problem is that the Intent show me only the Phone instead all the info added.

ContactsContract.Intents.Insert.ACTION if you want to interact before create it:
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION,ContactsContract.Contacts.CONTENT_URI);
intent.putExtra(ContactsContract.Intents.Insert.NAME, getName());
intent.putExtra(ContactsContract.Intents.Insert.COMPANY, getCompany());
intent.putExtra(ContactsContract.Intents.Insert.EMAIL, getEmail());
intent.putExtra(ContactsContract.Intents.Insert.PHONE, getPhone());
intent.putExtra(ContactsContract.Intents.Insert.POSTAL, getAddress());
startActivity(intent);
This works pretty well. I hope this will help you.

This site (http://wiresareobsolete.com/2011/10/simplifying-interaction-with-contacts/) shows and gives examples) that SHOW_OR_CREATE_CONTACT can only trigger off "tel" or "mailto"/email for searches.

Related

Open a contact by id from my application [duplicate]

Is it possible to open an android contact card by contact's ID? It works with the phone-number. Here is an example, if I use
Intent i = new Intent();
i.setAction(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
i.setData(Uri.fromParts("tel", "123456", null)); //<---- Change here from Phone to IDcontext.startActivity(i);
But I want to open this contact card by ID, for example if the phone-number from the contact would change.
use ACTION_VIEW and either build a contact URI using the contact ID or use the contact lookup URI if you already have it (preferred).
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);
You would use the following URI:
Uri.Builder newUriBuilder = ContactsContract.Contacts.CONTENT_LOOKUP_URI.buildUpon();
newUriBuilder.appendPath("/").appendPath(theContactKey)
i.setData(newUriBuilder.build());
You will find more details about how this URI works by looking at the API documentation for CONTENT_LOOKUP_URI.
I was trying to open a contact card using the listed here methods, but somehow the contacts activity was closing immediately after it was opening.
it seemed that the contact activity didn't accept my old content uri.
I resolved this problem using the getLookupUri (long contactId, String lookupKey) method of ContactsContract.Contacts class for obtaining the right content uri https://developer.android.com/reference/android/provider/ContactsContract.Contacts.html#getLookupUri(long, java.lang.String)
So the code for opening a contact card becomes:
Intent intent = new Intent(Intent.ACTION_VIEW);
String lookupKey = phonesCursor.getString(phonesCursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup.LOOKUP_KEY));
long contactId = phonesCursor.getLong(phonesCursor.getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID));
Uri uri = ContactsContract.Contacts.getLookupUri(contactId, lookupKey);
intent.setData(uri);
startActivity(intent);

Send SMS to multiple recipients via Intent

I am trying to send SMS to multiple recipients viaINTENT. I tried the following to do it:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", etmessage.getText().toString());
intent.setData(Uri.parse("smsto:" + returnedItems));
intent.setType("vnd.android-dir/mms-sms");
mcontext.startActivity(intent);
Where returnedItems is of Contact Numbers
But the problem is that my recipients numbers are not setting on TO section on SMS INTENT where TEXT is displayed on TEXT section.
Make sure that the numbers are seperated by ; .
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:1234456;234567"));
smsIntent.putExtra("sms_body", etmessage.getText().toString());
startActivity(smsIntent);
always works for me!
Did you tried below ?
Intent mIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:999999;888888"));
I also found out ";" is not working in Samsung device. You have to add "," instead of ";" for samsungs devices.
Intent mIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:999999,888888"));
Also check this answer
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,Uri.parse("smsto:" + pointsList));
smsIntent.putExtra("sms_body", "Hi Friends & Families, My Location is feeling unsafe in this location");
startActivity(smsIntent);
pointsList is something like ArrayList, for example [8777675673,8566463454,7776666664].
It is working fine.
I have solved this by the following way.
Intent intent = new Intent(Intent.ACTION_SEND);
String numbers = "1234567890;9876543210;453678920"
intent.putExtra("address", numbers);
context.startActivity(Intent.createChooser(intent, context.getString(R.string.share_image)));
The numbers are separated by semi-colon (;). I read in some mobile phones the numbers need to separated by comma (,).
Hope this will help.

display contact with given display name android

SO,how do i do it? I have tried the following
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
context.startActivity(intent);
The above works only with mailto or tel, what about name?
you can also send Person Name using Intents.Insert.NAME with Intent as:
Intent intent = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT);
intent.setData(Uri.fromParts("mailto","example#email.com", null));
// add name here
intent.putExtra(Intents.Insert.NAME, sender_Name_here);
context.startActivity(intent);

how to launch photo gallery with search parameter in Android programatically

I am trying to programatically launch or open the photo gallery after passing a photo name search parameter.
I am new at this. I am thinking maybe intents can be used but not sure so I am wondering if anyone could please point me in the right direction. Preferably with some code examples.
Much thanks.
RE-EDIT
As requested, this is the code I have so far..
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// CAMERA_PIC_REQUEST = 2600;
cameraIntent = Intent.createChooser(intent,"Select Picture");
you can try follow code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(photoUri);
context.startActivity(intent);
I think this is what you mean, correct me if I'm wrong:
String nameOfPhotoToBeRetrieved = "myPhoto";
String WHERE = "TITLE ="+nameOfPhotoToBeRetrieved;
Then you can use the following line to deliver a result to your cursor/listener:
CursorLoader(context,content_uri,null,WHERE,null,null).deliverResult(myCursor);

Start Google search query from activity - Android

I was wondering if there is an easier way (or any way) to start a Browser with a Google search query. For example user can select a certain word or phrase and click a button and the activity will start the browser with the Google search query.
Thank you.
The Intent class defines an action specifically for web searches:
http://developer.android.com/reference/android/content/Intent.html#ACTION_WEB_SEARCH
Here's an example of how to use it:
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, query); // query contains search string
startActivity(intent);
You can do this quite easily with a few lines of code (assuming you want to search Google for 'fish'):
String escapedQuery = URLEncoder.encode(query, "UTF-8");
Uri uri = Uri.parse("http://www.google.com/#q=" + escapedQuery);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
Otherwise, if you would rather start up your own Activity to handle the browsing, you should be able to do so with a WebView: http://developer.android.com/reference/android/webkit/WebView.html
I think the better answer here is #zen_of_kermit's. It would be nice though, if Android allowed a user to provide the Search engine has an extra though for the ACTION_WEB_SEARCH, rather than just using Google.
the # gave me trouble:
Uri uri = Uri.parse("https://www.google.com/search?q="+query);
Intent gSearchIntent = new Intent(Intent.ACTION_VIEW, uri);
activity.startActivity(gSearchIntent);
I recently tried this. This appears to work fine. If any modifications to be done let me know as I am new to android development.
mEdit = (EditText)findViewById(R.id.editText);
in your click view,
String q = mEdit.getText().toString();
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH );
intent.putExtra(SearchManager.QUERY, q);
startActivity(intent);
String Search= null;
try {
Search= URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Uri uri = Uri.parse("http://www.google.com/#q=" + Search);
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
});

Categories

Resources