HTML/JavaScript小工具

HTML/JavaScript小工具

2012年11月29日 星期四

檢查隱含intent是否可執行!


當中幾個比較關鍵的的方法如下:

PackageManager packageManager = getPackageManager(); 取得管理器
List<ResolveInfo> activities = packageManager.queryIntentActivities(mapIntent, 0);查詢Intent是否有相對應的程式
boolean isIntentSafe = activities.size() > 0;如果activities (有相對的應用程式)大於零isIntentSafe 就是true

// Build the intent
Uri location = Uri.parse("geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+California");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location);

// Verify it resolves
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);
}

沒有留言:

張貼留言