如何判斷某個Activity 的Action, Broadcast ,ContentProvi...

// 如何判斷某個Activity的Action的應用程序是否安裝
  PackageManager pm = getPackageManager();
  // 指定要檢測的Activity action 好比 com.android.phone.action.TOUCH_DIALER
  Intent intent = new Intent("com.android.phone.action.TOUCH_DIALER");
  // 在系統中查詢指定的Activity Action
  List<ResolveInfo> resolveInfo = pm.queryIntentActivities(intent, PackageManager.GET_INTENT_FILTERS);
  if (resolveInfo.size() == 0)
   System.out.println("不存在該Action"); android

  // 指定要查找的Broadcast Action
  Intent in = new Intent("mobile.android.MYBROADCAST");
  // 在系統中查找指定的Broadcast Action
  List<ResolveInfo> queryBroadcastReceivers = pm.queryBroadcastReceivers(intent, PackageManager.GET_INTENT_FILTERS);
  if (queryBroadcastReceivers.size() == 0) {
   System.out.println("不存在該廣播");
  }
  // 判斷指定的ContentProvider是否存在只須要根據ContentResolver對象相應的方法的返回值進行判斷便可
  Uri uri = Uri.parse("content://mobile.android.regioncontentprovider/cities");
  Cursor cursor = getContentResolver().query(uri, new String[] { "city_code as _id", "city_name" }, null, null, null);
  if (cursor == null)
   System.out.println("不存在此Uri");
 } ide

//.......判斷Sevice 這裏指的是AIDL Service spa

if(bindService(new Intent("mobile.android.IMyService"),serviceConnection,Context.BIND_AUTO_CREATE)){ code

//不存在 對象

} ci

相關文章
相關標籤/搜索