现在的位置: 首页 > 综合 > 正文

Android Training精要(四) Intent注意事项

2014年08月29日 ⁄ 综合 ⁄ 共 567字 ⁄ 字号 评论关闭

判断有处理Intent的Activity

PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0); 
boolean isIntentSafe = activities.size() > 0; 
 
// Start an activity if it's safe 
if (isIntentSafe) { 
    startActivity(mapIntent); 
}

將可以處理Intent的所有app列表做成下拉選擇框的形式

Intent intent = new Intent(Intent.ACTION_SEND); 
// Always use string resources for UI text. 
// This says something like "Share this photo with" 
String title = getResources().getString(R.string.chooser_title); 
// Create and start the chooser 
Intent chooser = Intent.createChooser(intent, title); 
startActivity(chooser);


抱歉!评论已关闭.