Android ACTION_PICK phone number of specific contact - android

I know how to create an intent to let the contacts app display a specific contact:
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, mMyLookupKey);
intent.setData(uri);
startActivity(intent);
I also know how to create an intent to ask the contacts app to let me PICK a phone number:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
// Explicitly set the 'type' to 'phone numbers' //
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, REQUEST_PHONENR);
Just now I have been trying to combine these to make it possible to pick a phone number from a specific contact:
Intent intent = new Intent(Intent.ACTION_PICK);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, mMyLookupKey);
intent.setData(uri);
// Explicitly set the 'type' to 'phone numbers'
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, REQUEST_PHONENR);
Does somebody know is this is possible?

Intent pickContactIntent = new Intent(Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI);
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, 0);

Related

When I am browsing a file using intents it's not going to File Manager?

When i click on the Browse button i have added below code:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType("*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
It shows FileManager in some devices like Redmi,Asus,Micromax.But it is not showing in Samsung phones,it's not going to file manager
How to get FileManager in Samsung phones to select a file?
try this is working for me
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent , CHOOSE_FILE_REQUESTCODE);
for Samsung Devices
String manufactures = android.os.Build.MANUFACTURER;
if(manufactures.equalsIgnoreCase("samsung")){
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
startActivityForResult(intent, CHOOSE_FILE_REQUESTCODE);
}
Replace
Intent intent = new Intent(Intent.ACTION_VIEW);
as
Intent intent = new Intent(Intent.GET_CONTENT);
EDIT
#Hanuman i think that single solution that fits all models doesn't exist, all intents with "actions" have to be processed by choosers. If you use >= 4.4 devices, I recommend
Storage Access Framework

Need to find all Messaging Apps in android

I need to find all applications (among installed ones) that can open SMS. I have already found Gallery applications through the following method:
PackageManager pm = getPackageManager();
Intent newIntent = new Intent(Intent.ACTION_VIEW);
newIntent.setType("image/*");
allApps = pm.queryIntentActivities(newIntent, PackageManager.MATCH_DEFAULT_ONLY);
It gives me the list of all apps that can open images. Is there any similar way by which I can find all apps that can open SMS Messages?
You need to set set type as vnd.android-dir/mms-sms
Try this code :
Uri uri = Uri.parse("smsto:123456789");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
intent.putExtra("sms_body", "SMS text");
OR
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("sms_body", "SMS text");
intent.putExtra("address", "123456789");
intent.setType("vnd.android-dir/mms-sms");
Hop it will help you :)
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setType("vnd.android-dir/mms-sms");
startActivity(intent);
Try this?
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_VIEW);
sendIntent.putExtra(Intent.EXTRA_TEXT,"Your Text");
sendIntent.setData(Uri.parse("sms:"));
startActivity(sendIntent);

how to open native contact card by URI

Can someone please explain me how to open contact native for specific contact URi
I manage to resolve the contact URI by:
Uri lookupUri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(displayName));
and then I tried do this:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, "555");
context.startActivity(intent);
but it's only open the native address book without any resolving
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 can retrieve the contactId by browsing using contentResolver:
id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
name = cur.getString( cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
Log.d(tag, "Id: "+ id+"\t Name: "+name);
After you get the cursor of contacts and the index of a particular contact, get the Uri and start activity with intent of ACTION_VIEW as below:
cursor.moveToPosition(position); // or cursor.moveToFirst() if single contact was selected.
long id = cursor.getLong(cursor.getColumnIndex(ContactsContract.Contacts._ID));
String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(ContactsContract.Contacts.getLookupUri(id, lookupKey));
try {
context.startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
The accepted answer does not work when Android Messages is not the user's default SMS app. For some reason the intent goes through Android Messages before opening the contact details, and when the app is not default it takes you to their SMS permissions activity.
The below intent uses a slightly different URI: CONTENT_LOOKUP_URI instead of CONTENT_URI, and it works no matter which texting app the user is using.
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_LOOKUP_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);

Only show contacts with phone numbers?

This code:
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK);
Shows all contacts in phone.
It's possible show contacts with only phone number?
Thanks!
Try this code. It shows only contacts with phone number, you should set the type of contacts (with phone numbers only):
Intent intent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(intent, 1);

Android. Opening a contact in through intent using contact_id or contact_name

I am using ContactsContract API in Android to get the list of contacts. The is working fine.
Now I want that when I click on a name in that list an intent is generated that will open the contact in the android contact manager.
The following code crashes the app:
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(ContactsContract.Contacts.CONTENT_URI + "/" + ContactsContract.Contacts._ID));
kindly help me out here with this intent
This should show the contacts 'card' in the android contact manager
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactID));
intent.setData(uri);
context.startActivity(intent);

Categories

Resources