Android Intent defaults - detect and clear

2019-01-26 00:59发布

Is there a way to detect that a phone has a default application chosen for an intent such as android.intent.action.SEND ?

Is there a way to clear the default application via code?

I'd like to give the user an option to remove the default or at least show a screen telling them how to do it manually, if I can detect it.

2条回答
迷人小祖宗
2楼-- · 2019-01-26 01:31

Use 2-step detection of defaults:

PackageManager.queryIntentActivities to get all activities for Intent, PackageManager.resolveActivity to get resolved.

If resolved one is in the list returned by queryIntentActivities, then there will be no "Complete action using" dialog, thus "default" activity was set.

查看更多
贪生不怕死
3楼-- · 2019-01-26 01:33

Take a look at PackageManager. With it, you can determine how an Intent will be handled with resolveActivity(intent). It looks like the method for clearing the preference (clearPackagePreferredActivities) only works on your own package.

查看更多
登录 后发表回答