读书人

PackageManager-gt;resolveActivity查询

发布时间: 2012-09-24 13:49:41 作者: rapoo

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
intentAn intent containing all of the desired specification (action, data, type, category, and/or component).
flagsAdditional 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的作用一样。

读书人网 >移动开发

热点推荐