Activity间通过隐式intent跳转,在发出intent之前必须通过resolveActivity检查,避免找不到合适的调用组件,造成ActivityNotFoundException的异常
- 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);
- }
- }