The contacts on the android phone come with settings like "Filter Contacts" that lets the user set things like "Show only contacts that have phone numbers" and "Only show contacts that are online", and which sets of contacts to display (eg, phone only, phone and google etc.).
When doing this
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
is there any way to get those filters applied to the contacts list? By default it seems to return everything. If you can't, is there some way to access those settings to see what they are, so I can build my own contacts picker list to match how the phone user has set their default? This only needs to work for Android 2 up.
(The ideal option would be a way to invoke the contact picker that lets the user also set the filters from in there.)
I think if you pass a URI to the intent like the one shown here, you should be able to apply your filter. So you'd do something like this:
Intent intent = new Intent(Intent.ACTION_PICK, PhoneLookup.CONTENT_FILTER_URI);
intent.setType(ContactsContract.Contacts.CONTENT_TYPE);
startActivityForResult(intent, PICK_CONTACT);
Related
I know that if I create an Intent like this:
val contactPickerIntent = Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI)
startActivityForResult(contactPickerIntent, request_code)
I will be able to pick a contact from my Contacts list.
And if i set the intent like this:
val contactPickerIntent = Intent(Intent.ACTION_VIEW, ContactsContract.Contacts.CONTENT_URI)
I will be able to go into the selected contact details (from within the contacts app) but i won't be able to pick anything from it.
The thing is I need to open the contact's details and select one of it's email addresses, in case he has more than one, and pick it.
Is there a way to do that?
You can change your picker from a Contact picker to an Email picker:
Intent contacts = new Intent(Intent.ACTION_PICK, CommonDataKinds.Email.CONTENT_URI); // Note the Email!
startActivityForResult(contacts, PICK_CONTACTS);
See: https://developer.android.com/guide/components/intents-common#Contacts
I am trying to open gallery on Nexus 7 with Android 6.0. It does not have in built gallery, but it does have the Google Photos app.
I am using the following code to open the gallery :
Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(i, "Select Picture"), PICK_IMAGE_REQUEST);
The above code works well in all the versions below 6.0. And Please note that I am already using RUN TIME PERMISSIONS for accessing gallery and have given the permission to access gallery / or externa storage.
Now when the code is executed, I get a transparent screen with heading "Select Picture" and in the middle a text No Apps can perform this action.
Now what do I do to pick or choose image and use in my app.
Any help is appreciated.
Thanks
I am using the following code to open the gallery
That code has nothing to do with a "gallery". That code is requesting to pick a piece of content from a particular collection of content. There may be zero, one, or several activities on the device that offer to support that Intent structure.
The above code works well in all the versions below 6.0
Only on devices that happen to have one or more activities that satisfies that Intent structure.
Now what do I do to pick or choose image and use in my app.
Intent i = new intent(Intent.ACTION_GET_CONTENT).setType("image/*");
// use PackageManager to see if there is anything that supports this
// Intent structure, or just blindly make the following call and handle
// the ActivityNotFoundException
startActivityForResult(i, PICK_IMAGE_REQUEST);
I am using this code , so that only gallery opens and not any other option to pick image
There is nothing in your code that limits it to just a "gallery".
Not allowed to comment because I don't have enough points. But here's just a suggestion, how about if you just passed the intent directly? Like this:
startActivityForResult(i, PICK_IMAGE_REQUEST);
Use this line of code rather than what you have done
Intent i = new intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, PICK_IMAGE_REQUEST);
Intent pickContactIntent = new Intent(Intent.ACTION_PICK,Uri.parse("content://contacts"));
pickContactIntent.setType(ContactsContract.CommonDataKinds.Phone.CONTENT_TYPE);
I saw the intent above is only allowed to pick the contacts but I need to pick call logs, favorite, contact just like Android OS Contact Book , How should i achieve this ?
Is there any Intent which allows this or do we need to code it ?
I want is to hide all contacts without phone numbers in phonebook from my application..
Just like phonebook do, When you go to phonebook -> settings there is a checkbox which states that "Contacts with phone number only" I want to implement this feature in my app
I need a method (code) to navigate users to
phonebook -> settings (activity) (System app)
from my application activity.
or worse case hide all contacts without phone number through database. So that phonebook can filter out.
Currently i found
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, 123);
Above code opens phone book but i want to open phone book -> settings page.
In sum i want to make phonebook contents "contacts with phone numbers" from my application
I need a method (code) to navigate users to phonebook -> settings (activity) (System app)
There are hundreds, perhaps thousands, of Android phones. None will necessarily be the same with respect to their "phonebook" app. None of those "phonebook" apps necessarily have the feature you seek -- some may, some many not. And, most likely, none have a documented and supported Intent structure for getting to a screen within the app to control the setting that they may or may not have.
I want is to hide all contacts without phone numbers in phonebook from my application
Then you will need to not use the "phonebook" app, but instead display contacts yourself, via the READ_CONTACTS permission and the ContactsContract ContentProvider.
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
startActivityForResult(intent, PICK_CONTACT);
Well, I have sucessfully developed a Contacts application for Android as my major project. I believe this is quite simple. Here is code how I did it.
Cursor c = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
null,
ContactsContract.Contacts.HAS_PHONE_NUMBER + " = 1",
null,
ContactsContract.Contacts.DISPLAY_NAME+" COLLATE LOCALIZED ASC");
mAdapter = new MyAdapter(this,
R.layout.single_cell,
c,
new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME},
new int[]{R.id.disp_name},
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
listview.setAdapter(mAdapter);
And, in MyAdapter, I have extended SimpleCursorAdapter and over rided bindView() to take advantage of efficiency of SimpleCursorAdapter. However, you need a permission to read contacts. In your android-manifest file. Please mention,
<uses-permission android:name="android.permission.READ_CONTACTS"/>
Hope, it helps.
I would like to reuse the native Contact Picker of a User's device by doing the following:
public void doLaunchContactPicker(View view) {
Intent contactPickerIntent = new Intent(Intent.ACTION_PICK,
Contacts.CONTENT_URI);
// Made up code that I am sure doesn't exist
contactPickerIntent.putExtra("MyRemote3rdPartyContactList", remoteContacts)
startActivityForResult(contactPickerIntent, CONTACT_PICKER_RESULT);
}
However, instead of looking at their contacts that are on the device, I would like to re-configure the Contact UI to point at a Custom Contact Provider that I populate via webservice call in my app.
How would I go about doing this if it is possible?
Technically not possible: the default Contact picker doesn't have any code to let you feed it a different data source.
If you really want you can pop open the source and poke at it: maybe you can reuse it for your purposes.