android 为什么从 resolveActivity() 获得的 ResolveInfo 与从 queryIntentActivities() 获得的不同
android why the ResolveInfo got from resolveActivity() is different than from queryIntentActivities()
从 resolveActivity()
和 queryIntentActivities()
查看 ResolveInfo
return 时,
为什么 ResolveInfo
与这两个意图相同的调用不同?
viewIntent
是 Intent(Intent.ACTION_VIEW, Uri.parse(deeplinkData)
,而从 resolveActivity 编辑的 return 具有不相关的 packagename/name:
ResolveInfo info = pm.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
System.out.println("+++ 111 resolveActivity(), info.activityInfo.packageName: "+info.activityInfo.packageName+",\ninfo.activityInfo.name: "+info.activityInfo.name);
它有日志:
+++ 111 resolveActivity(), info.activityInfo.packageName: android,
info.activityInfo.name: com.android.internal.app.ResolverActivity
其中使用 queryIntentActivities
List<ResolveInfo> resInfo = pm.queryIntentActivities(viewIntent, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
System.out.println("+++ queryIntentActivities(), info.activityInfo.packageName: "+ (info.activityInfo.packageName));
System.out.println("+++ +++ queryIntentActivities(), info.activityInfo.name: "+ (info.activityInfo.name));
......
}
}
有日志:
+++ queryIntentActivities(), info.activityInfo.packageName: com.client.android.debug
+++ +++ queryIntentActivities(), info.activityInfo.name: com.client.android.NewsActivity
+++ queryIntentActivities(), info.activityInfo.packageName: com.android.chrome
+++ +++ queryIntentActivities(), info.activityInfo.name: com.google.android.apps.chrome.IntentDispatcher
resolveActivity()
returns 如果您调用 startActivity()
将启动的组件。那将是:
null
如果没有匹配项或者您没有在 Android 11+ 上设置包可见性规则
- activity 将从某个应用程序启动,如果只有一个匹配项或者用户选择默认值
- 选择器activity,如果有2+个匹配且没有默认值
在您的情况下,您将获得选择器 activity (com.android.internal.app.ResolverActivity
)。
从 resolveActivity()
和 queryIntentActivities()
查看 ResolveInfo
return 时,
为什么 ResolveInfo
与这两个意图相同的调用不同?
viewIntent
是 Intent(Intent.ACTION_VIEW, Uri.parse(deeplinkData)
,而从 resolveActivity 编辑的 return 具有不相关的 packagename/name:
ResolveInfo info = pm.resolveActivity(viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
System.out.println("+++ 111 resolveActivity(), info.activityInfo.packageName: "+info.activityInfo.packageName+",\ninfo.activityInfo.name: "+info.activityInfo.name);
它有日志:
+++ 111 resolveActivity(), info.activityInfo.packageName: android,
info.activityInfo.name: com.android.internal.app.ResolverActivity
其中使用 queryIntentActivities
List<ResolveInfo> resInfo = pm.queryIntentActivities(viewIntent, 0);
if (!resInfo.isEmpty()){
for (ResolveInfo info : resInfo) {
System.out.println("+++ queryIntentActivities(), info.activityInfo.packageName: "+ (info.activityInfo.packageName));
System.out.println("+++ +++ queryIntentActivities(), info.activityInfo.name: "+ (info.activityInfo.name));
......
}
}
有日志:
+++ queryIntentActivities(), info.activityInfo.packageName: com.client.android.debug
+++ +++ queryIntentActivities(), info.activityInfo.name: com.client.android.NewsActivity
+++ queryIntentActivities(), info.activityInfo.packageName: com.android.chrome
+++ +++ queryIntentActivities(), info.activityInfo.name: com.google.android.apps.chrome.IntentDispatcher
resolveActivity()
returns 如果您调用 startActivity()
将启动的组件。那将是:
null
如果没有匹配项或者您没有在 Android 11+ 上设置包可见性规则
- activity 将从某个应用程序启动,如果只有一个匹配项或者用户选择默认值
- 选择器activity,如果有2+个匹配且没有默认值
在您的情况下,您将获得选择器 activity (com.android.internal.app.ResolverActivity
)。