如何为特定的 mime 定义默认 ACTION_VIEW 意图?
我正在尝试查找哪个设备使用默认的 Intent
来支持特定的 mime 类型,代码如下:
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
List<ResolveInfo> lri = pm.queryIntentActivities(intent, 0);
for(ResolveInfo resolveInfo:lri)
{
if(Me.DEBUG)
Log.i(TAG, "Resolved intent="+resolveInfo.activityInfo.packageName+
", default="+resolveInfo.isDefault+
", order="+resolveInfo.preferredOrder+
", match="+resolveInfo.match+
", priority="+resolveInfo.priority);
if(resolveInfo.isDefault)
{
intent=pm.getLaunchIntentForPackage(resolveInfo.resolvePackageName);
intent.setDataAndType(uri, mimeTypes.getMimeTypeString(name));
break;
}
}
return intent;
这段代码有什么问题? ResolveInfo 永远不会返回默认值...Logcat 报告始终相同,例如:
已解决intent=com.android.htmlviewer,默认=false,order=0, 匹配=6324224,优先级=0 已解决意图=com.sec.print.mobileprint, 默认 = false,顺序 = 0,匹配 = 6324224,优先级 = 0 已解决 意图= com.qo.android.htc,默认= false,顺序= 0,匹配= 6324224, 优先级 = 0 已解决意图 = org.coolreader,默认 = false,顺序 = 0, 匹配=6324224,优先级=0 已解决意图=xcxin.fileexpert, 默认 = false,顺序 = 0,匹配 = 6324224,优先级 = 0 已解决 意图= com.opera.browser,默认= false,顺序= 0,匹配= 6324224, 优先级=0 解析intent=com.dropbox.android,默认=false, 顺序=0,匹配=6324224,优先级=0
尽管选择器上有默认标记的用户“将此设为默认”复选框!
I'm trying to find default Intent
which device is using to support specific mime type, code like:
PackageManager pm = this.getPackageManager();
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, mimeType);
List<ResolveInfo> lri = pm.queryIntentActivities(intent, 0);
for(ResolveInfo resolveInfo:lri)
{
if(Me.DEBUG)
Log.i(TAG, "Resolved intent="+resolveInfo.activityInfo.packageName+
", default="+resolveInfo.isDefault+
", order="+resolveInfo.preferredOrder+
", match="+resolveInfo.match+
", priority="+resolveInfo.priority);
if(resolveInfo.isDefault)
{
intent=pm.getLaunchIntentForPackage(resolveInfo.resolvePackageName);
intent.setDataAndType(uri, mimeTypes.getMimeTypeString(name));
break;
}
}
return intent;
What's wrong with this code? ResolveInfo never returns default one... Logcat reports always the same, like:
Resolved intent=com.android.htmlviewer, default=false, order=0,
match=6324224, priority=0 Resolved intent=com.sec.print.mobileprint,
default=false, order=0, match=6324224, priority=0 Resolved
intent=com.qo.android.htc, default=false, order=0, match=6324224,
priority=0 Resolved intent=org.coolreader, default=false, order=0,
match=6324224, priority=0 Resolved intent=xcxin.filexpert,
default=false, order=0, match=6324224, priority=0 Resolved
intent=com.opera.browser, default=false, order=0, match=6324224,
priority=0 Resolved intent=com.dropbox.android, default=false,
order=0, match=6324224, priority=0
Though there's default marked user as "make this the default" checkbox on the chooser!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里,“默认”意味着用户通过先前调用此 Intent 并选中选择器上的“使其成为默认”复选框来设置默认值。如果尚未完成,则不存在默认值。
Here, "default" means the user set a default, by having this
Intent
invoked previously and checking the "make this the default" checkbox on the chooser. If that has not already been done, there is no default.