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);
Related
I want to be able to pick only videos from gallery but I only found tutorials that select images but I only want to be able to select videos.
Can anyone help?
For example, when you use an intent, you can set the type of your intent. Here I'm using "video/*" to get all videos of my device.
Intent galleryIntent = new Intent(Intent.ACTION_PICK);
galleryIntent.setType("video/*");
startActivity(galleryIntent);
Try this code..
protected int REQUEST_TAKE_GALLERY_VIDEO = 3;
Intent intent = new Intent();
intent.setType("video/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,"Select Video"),REQUEST_TAKE_GALLERY_VIDEO);
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
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);
I'm trying to select contacts depending on their information, it's working for phone numbers (as far as I can see); but when I try to pick contacts with only email it fails with the following error:
Caused by: android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.GET_CONTENT typ=vnd.android.cursor.item/email_v2 }
Here's my code (or rather the important part):
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
if( SMS )
intent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE);
if( EMAIL )
intent.setType(ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE);
startActivityForResult(intent, PICK_CONTACT);
I think you should be using Intent intent = new Intent(Intent.ACTION_PICK, uri), where uri is one of CommonDataKinds.Email.CONTENT_URI or CommonDataKinds.Phone.CONTENT_URI. That way, it'll display only contacts with an email or phone.
Code show an error when try declare a new Uri
follow code:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, new Uri("content://contacts"));
show an error
"Cannot instantiate the type Uri"
Instead of constructing a Uri, use the static parse method to create it:
Uri.parse("content://contacts");
Although, since you are accessing contacts, you should probably prefer using the static field CONTENT_URI from the Contacts class. See the SDK reference for Contacts.
This would make your code:
Intent pickContactIntent = new Intent(Intent.ACTION_PICK, Contacts.CONTENT_URI);
You should use:
Intent pickContactIntent = new Intent( Intent.ACTION_PICK,ContactsContract.Contacts.CONTENT_URI );
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
startActivityForResult(pickContactIntent, PICK_CONTACT_REQUEST);