Android Intent defaults - detect and clear

吃可爱长大的小学妹 提交于 2019-12-29 07:19:28

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4675405/android-intent-defaults-detect-and-clear

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!