Android的意图默认值 - 检测和清除意图、默认值、Android

2023-09-06 14:11:58 作者:注定为你飞蛾扑火ヘ

有没有一种方法来检测手机已经选择了一个意图默认的应用程序,如 android.intent.action.SEND

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

有没有办法来清除通过code,其默认的应用程序?

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.

推荐答案

看看PackageManager.有了它,你可以决定如何将意图将与resolveActivity(意向)处理。它看起来像的方法清除preference(clearPackage preferredActivities)只适用于你自己的包。

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.