Reputation: 81
I'm designing an app which requires opening the contacts app with a search. I'm using the code:
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.putExtra(SearchManager.QUERY, name);
startActivity(intent);
The problem I have is that this opens the app chooser and displays about 40 apps for the user to choose from, which could be confusing. Is there any way to automatically set the contacts app as default or even to minimise the list?
I have tried using the command:
intent.setData(ContactsContract.Contacts.CONTENT_URI);
This seems to work for other types of contact related activities such as ACTION_VIEW, but when I add it to an ACTION_SEARCH intent the app simply crashes.
Thank you.
Upvotes: 2
Views: 1234
Reputation: 640
Although I agree with Emile that it is against the way how Android is meant to work, there is a way how you can create your own chooser and make even a default app that will fire for that intent. To make a default app will mean that you will specify that app in your apps Shared Preferences.
More on that in different thread.
Upvotes: 1
Reputation: 11721
I don't believe this is something you can set as the developer of an app, as that would override all other apps of a similar ilk. As such this is set as a user choice only.
This explains how users set an app to be there default. http://www.howtogeek.com/howto/43135/how-to-change-the-default-application-for-android-tasks/
No, i don't believe there is anyway to override this. Taking user choice away is a bad thing, you'd risk lots of people getting up set and rating your app poorly.
I've read your question several times, each time i realised you were asking something different. Still i think this link might put you on the right track, it answers a similar question.
How to call Android contacts list?
The jist of it seems to be that you need to target the contacts app directly with this line
Intent intent = new Intent(Intent.ACTION_PICK, ContactsContract.Contacts.CONTENT_URI);
Hope that helps.
Upvotes: 1