如何判断某个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");

  // 指定要查找的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");
 }

//.......判断Sevice 这里指的是AIDL Service

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

//不存在

}

你可能感兴趣的:(如何判断某个Activity 的Action, Broadcast ,ContentProvi...)