private void listing502() {
/**
* Listing 5-2: Implicitly starting an Activity
*/
if (somethingWeird && itDontLookGood) {
// Create the implicit Intent to use to start a new Activity.
Intent intent =
new Intent(Intent.ACTION_DIAL, Uri.parse("tel:555-2368"));
// Check if an Activity exists to perform this action.
PackageManager pm = getPackageManager();
ComponentName cn = intent.resolveActivity(pm);
if (cn == null) {
// If there is no Activity available to perform the action
// Check to see if the Market is available.
Uri marketUri =
Uri.parse("market://search?q=pname:com.myapp.packagename");
Intent marketIntent = new
Intent(Intent.ACTION_VIEW).setData(marketUri);
// If the Market is available, use it to download an application
// capable of performing the required action. Otherwise log an
// error.
if (marketIntent.resolveActivity(pm) != null)
startActivity(marketIntent);
else
Log.d(TAG, "Market client not available.");
}
else
startActivity(intent);
}
}
【intent】确定Intent能否解析
最新推荐文章于 2021-05-27 08:37:17 发布