`

PackageManager-->resolveActivity查询是否有符合条件的Activity

阅读更多
Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.parse(url), mimetype);
            if (getPackageManager().resolveActivity(intent,
                        PackageManager.MATCH_DEFAULT_ONLY) != null) {
                // someone knows how to handle this mime type with this scheme, don't download.
                try {
                    startActivity(intent);
                    return;
                } catch (ActivityNotFoundException ex) {
                    if (Config.LOGD) {
                        Log.d(LOGTAG, "activity not found for " + mimetype
                                + " over " + Uri.parse(url).getScheme(), ex);
                    }
                    
                }

查询是否有符合Uri.parse(url), mimetype这两个条件的Activity

public abstract ResolveInfo resolveActivity (Intent intent, int flags)

Since: API Level 1
Determine the best action to perform for a given Intent. This is how resolveActivity(PackageManager) finds an activity if a class has not been explicitly specified.
Parameters
intent An intent containing all of the desired specification (action, data, type, category, and/or component).
flags Additional option flags. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT.
Returns
Returns a ResolveInfo containing the final activity intent that was determined to be the best action. Returns null if no matching activity was found.
See Also
MATCH_DEFAULT_ONLY
GET_INTENT_FILTERS
GET_RESOLVED_FILTER


resolveContentProvider和resolveService的作用一样。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics