A great application should provide a function to let users set it as the preferred or default application. In this post, I will make a description on PreferredApplication
Before an application is about to be set as default, it has two possibilities. One is that there is already a default application and the other is no default application.
Detect the Default Application Exists or Not
This is really important. It determines what we should do next.
1 2 3 4 5 6 7 |
|
Result before I set Maxthon Browser as the default one. If no default one is set, the system will call the com.android.internal.app.ResolverActivity
1
|
|
Result after I set Maxthon Browser as the default one. If the default one is set just call the default activity
1
|
|
So it is really clear that you could use the following code to judge.
1 2 |
|
If the default one is already set
Just remove the preferred settings of the default application. However you could not do this in the code due to the permission control. It’s generally done by users manually. What you could do is lead the user to the clear default page(installedAppDetails)
1 2 3 4 5 |
|
Then you navigate the user to the installedAppDetails and you could show some tips to click Button Clear Default. When users go back from installedAppDetails to your application check is there any default appliction now. If the default application(in general, it’s not the previous one) remains repeat the above actions until there is not default one.
No default One
Now there is only one step to set ours as the default one. You could not do this in codes. It’s also required manual operation. What you could do is popup the selecting dialog and tip the use select your one.
1 2 3 4 5 6 7 8 |
|
The dialog is like this
What’s more, your tips is really essential. Make sure to notify that “Use by default for this action” should be checked.
How to Clear my own default
1 2 3 4 |
|
Note you could only clear packagePreferredActivities of your own.
A step into system control
the following settings is some content of /data/system/packages.xml
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Special
- What will system do if I install or uninstall a related application?
- Actually the system provide you a special chance to rechoose if a related activity is added or removed. When you click the url it should popup a dialog not use the previous preferred activity.
- When the system popup the choosing dialog?
- After some tests I guess the system will make a list of interested activities instantly. And then use the previous list to compare with the list stored in /data/system/packages.xml. If they are not the same, the choose dialog should be poped up.