答案 0 :(得分:1)
如果您与Intent
共享文件,则可以先创建Intent openWith
对象(但尚未运行)。然后列出所有可用的活动,如下所示:
PackageManager pm = (Activity)this.getPackageManager();
List<ResolveInfo> resInfo = pm.queryIntentActivities(openWith, 0);
for (int i = 0; i < resInfo.size(); i++) {
ResolveInfo ri = resInfo.get(i);
String packageName = ri.activityInfo.packageName;
String label = (String) ri.loadLabel(pm);
String activity = ri.activityInfo.name;
// choose needed packageName and activity here
}
然后将选定的packageName和activity对添加到&#34;打开的&#34;动作:
intent.setComponent(new ComponentName(packageName, activity));
并运行它。
答案 1 :(得分:1)
你想在你的应用程序中实现能力打开文件/网址,对吗? 这是doc https://developer.android.com/training/basics/intents/filters.html 因此,您的“观看者”活动必须具有像这样的意图过滤器
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT"/>
<data android:scheme="http|https" />
</intent-filter>