2

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.

user1216674
  • 81
  • 1
  • 4

2 Answers2

1

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.

Community
  • 1
  • 1
Emile
  • 11,451
  • 5
  • 50
  • 63
  • http://stackoverflow.com/questions/3133650/android-intent-to-open-users-preferred-browser talks about makeMainSelectorActivity see last answer by splash. – Emile Aug 19 '12 at 11:04
1

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.

Community
  • 1
  • 1
Martin Rajniak
  • 630
  • 8
  • 26
  • Unfortunately whilst you can make your own chooser, it doesn't allow you to specify whats apps appear (as far as i can tell) in the list. It does however allow you to ignore any default apps, forcing the user to choose each time. It looks like CommonsWare is equally interested in this topic, and might have examples on his site. Worth a look. – Emile Aug 19 '12 at 12:36
  • If you would like to just filter some of the apps from the chooser list, then use [createChooser()](http://developer.android.com/reference/android/content/Intent.html), where you can specify what apps you want to display. The downside of this is that you ignore preferred app chosen by the user. But then you as I have already said you can save the preference for your application and next time use the preferred application right away. – Martin Rajniak Aug 19 '12 at 16:32
  • "where you can specify what apps you want to display." thats the bit i couldn't see any reference to. Is it type of app, or app names? – Emile Aug 19 '12 at 21:04
  • try to have a look at flag named EXTRA_INTENT in intent class. when you use it with createChooser, you can specify what activities to display. – Martin Rajniak Aug 20 '12 at 07:38