如何为特定的 mime 定义默认 ACTION_VIEW 意图?

发布于 2024-12-18 05:16:40 字数 1525 浏览 0 评论 0原文

我正在尝试查找哪个设备使用默认的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰ゝ天使的微笑 2024-12-25 05:16:41

这里,“默认”意味着用户通过先前调用此 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文