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

时间:2011-11-25 18:25:29

标签: android android-intent default mime-types

我正在尝试查找默认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报告始终相同,如:

  

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已解决   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已解决   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

虽然在选择器上默认标记用户为“将其设为默认值”复选框!

1 个答案:

答案 0 :(得分:0)

此处,“默认”表示用户通过先前调用此Intent并选中选择器上的“将此设置为默认值”复选框来设置默认值。如果尚未完成,则没有默认值。