本文整理汇总了Java中android.content.pm.PackageManager.queryBroadcastReceivers方法的典型用法代码示例。如果您正苦于以下问题:Java PackageManager.queryBroadcastReceivers方法的具体用法?Java PackageManager.queryBroadcastReceivers怎么用?Java PackageManager.queryBroadcastReceivers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.pm.PackageManager
的用法示例。
在下文中一共展示了PackageManager.queryBroadcastReceivers方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findSystemApk
import android.content.pm.PackageManager; //导入方法依赖的package包/类
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
final Intent intent = new Intent(action);
for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
if (info.activityInfo != null &&
(info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
final String packageName = info.activityInfo.packageName;
try {
final Resources res = pm.getResourcesForApplication(packageName);
return Pair.create(packageName, res);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
}
}
return null;
}
示例2: getAvailableRewriters
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Retrieve rewriter available as plugin for csipsimple.
*
* @param ctxt context of application
* @return A map of package name => Fancy name of rewriter
*/
public static Map<String, String> getAvailableRewriters(Context ctxt) {
if (AVAILABLE_REWRITERS == null) {
AVAILABLE_REWRITERS = new HashMap<String, String>();
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(SipManager.ACTION_REWRITE_NUMBER);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
for (ResolveInfo resInfo : availables) {
ActivityInfo actInfos = resInfo.activityInfo;
Log.d(THIS_FILE, "Found rewriter " + actInfos.packageName + " " + actInfos.name);
if (packageManager.checkPermission(permission.PROCESS_OUTGOING_CALLS,
actInfos.packageName) == PackageManager.PERMISSION_GRANTED) {
String packagedActivityName = (new ComponentName(actInfos.packageName,
actInfos.name)).flattenToString();
AVAILABLE_REWRITERS.put(packagedActivityName,
(String) resInfo.loadLabel(packageManager));
}
}
}
return AVAILABLE_REWRITERS;
}
示例3: getAvailableCallHandlers
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Retrieve outgoing call handlers available as plugin for csipsimple Also
* contains stock call handler if available
*
* @param ctxt context of application
* @return A map of package name => Fancy name of call handler
*/
public static Map<String, String> getAvailableCallHandlers(Context ctxt) {
if (AVAILABLE_HANDLERS == null) {
AVAILABLE_HANDLERS = new HashMap<String, String>();
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(SipManager.ACTION_GET_PHONE_HANDLERS);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
for (ResolveInfo resInfo : availables) {
ActivityInfo actInfos = resInfo.activityInfo;
Log.d(THIS_FILE, "Found call handler " + actInfos.packageName + " " + actInfos.name);
if (packageManager.checkPermission(permission.PROCESS_OUTGOING_CALLS,
actInfos.packageName) == PackageManager.PERMISSION_GRANTED) {
String packagedActivityName = (new ComponentName(actInfos.packageName,
actInfos.name)).flattenToString();
AVAILABLE_HANDLERS.put(packagedActivityName,
(String) resInfo.loadLabel(packageManager));
}
}
}
return AVAILABLE_HANDLERS;
}
示例4: getAvailableThemes
import android.content.pm.PackageManager; //导入方法依赖的package包/类
public static HashMap<String, String> getAvailableThemes(Context ctxt){
HashMap<String, String> result = new HashMap<String, String>();
result.put("", ctxt.getResources().getString(R.string.app_name));
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(SipManager.ACTION_GET_DRAWABLES);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
Log.d(THIS_FILE, "We found " + availables.size() + "themes");
for(ResolveInfo resInfo : availables) {
Log.d(THIS_FILE, "We have -- "+resInfo);
ActivityInfo actInfos = resInfo.activityInfo;
ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
String label = (String) actInfos.loadLabel(packageManager);
if(TextUtils.isEmpty(label)) {
label = (String) resInfo.loadLabel(packageManager);
}
result.put(cmp.flattenToString(), label);
}
return result;
}
示例5: getReceiverName
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private ActivityInfo getReceiverName (String pkg,
PackageManager packageManager) {
Intent intent = new Intent();
intent.setPackage(pkg);
//intent.setAction(Constants.ACTION_RECEIVE_MESSAGE);
for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent,
PackageManager.GET_RESOLVED_FILTER |
PackageManager.GET_DISABLED_COMPONENTS)) {
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (!activityInfo.packageName.equals(pkg))
continue;
IntentFilter filter = resolveInfo.filter;
if (filter != null && filter.hasAction(Constants.ACTION_RECEIVE_MESSAGE)) {
return activityInfo;
}
}
// Not found
return null;
}
示例6: d
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static boolean d(Context context, String str, String str2) {
PackageManager packageManager = context.getPackageManager();
Intent intent = new Intent(str2);
intent.setPackage(context.getPackageName());
for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent, 0)) {
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (activityInfo != null && activityInfo.name.equals(str)) {
return true;
}
}
return false;
}
示例7: getRespondersForDataType
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Determines the set of providers who may be able to provide data of the specified type,
* based on their declared broadcast query receivers.
*/
public static Set<String> getRespondersForDataType(@NonNull Context context,
@NonNull String dataType) {
require(context, notNullValue());
require(dataType, notNullValue());
PackageManager packageManager = context.getPackageManager();
Intent intent = new Intent(dataType);
intent.addCategory(QueryUtil.BBQ_CATEGORY);
List<ResolveInfo> responderInfos =
packageManager.queryBroadcastReceivers(intent, PackageManager.GET_RESOLVED_FILTER);
HashSet<String> responders = new HashSet<>();
for (ResolveInfo info : responderInfos) {
responders.add(info.activityInfo.packageName);
}
return responders;
}
示例8: findSystemApk
import android.content.pm.PackageManager; //导入方法依赖的package包/类
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) {
final Intent intent = new Intent(action);
for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
if (info.activityInfo != null &&
(info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
final String packageName = info.activityInfo.packageName;
try {
final Resources res = pm.getResourcesForApplication(packageName);
return Pair.create(packageName, res);
} catch (NameNotFoundException e) {
Log.w(TAG, "Failed to find resources for " + packageName);
}
}
}
return null;
}
示例9: get
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Find and return partner details, or {@code null} if none exists. A partner package is marked
* by a broadcast receiver declared in the manifest that handles the
* {@code com.android.setupwizard.action.PARTNER_CUSTOMIZATION} intent action. The overlay
* package must also be a system package.
*/
public static synchronized Partner get(Context context) {
if (!sSearched) {
PackageManager pm = context.getPackageManager();
final Intent intent = new Intent(ACTION_PARTNER_CUSTOMIZATION);
for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) {
if (info.activityInfo == null) {
continue;
}
final ApplicationInfo appInfo = info.activityInfo.applicationInfo;
if ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
try {
final Resources res = pm.getResourcesForApplication(appInfo);
sPartner = new Partner(appInfo.packageName, res);
break;
} catch (NameNotFoundException e) {
Log.w(TAG, "Failed to find resources for " + appInfo.packageName);
}
}
}
sSearched = true;
}
return sPartner;
}
示例10: getDynCodecPlugins
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Retrieve all dynamic codec plugins available in the platform
* It will resolve for a given action available sip plugins
* @param ctxt Context of the application
* @param action Action of the plugin to be resolved
* For example {@link SipManager#ACTION_GET_EXTRA_CODECS}, {@link SipManager.ACTION_GET_VIDEO_PLUGIN}
* @return a map containing plugins infos and registrered component name as key
*/
public static Map<String, DynCodecInfos> getDynCodecPlugins(Context ctxt, String action){
if(!CACHED_RESOLUTION.containsKey(action)) {
HashMap<String, DynCodecInfos> plugins = new HashMap<String, DynCodecInfos>();
PackageManager packageManager = ctxt.getPackageManager();
Intent it = new Intent(action);
List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0);
for(ResolveInfo resInfo : availables) {
ActivityInfo actInfos = resInfo.activityInfo;
if( packageManager.checkPermission(SipManager.PERMISSION_CONFIGURE_SIP, actInfos.packageName) == PackageManager.PERMISSION_GRANTED) {
ComponentName cmp = new ComponentName(actInfos.packageName, actInfos.name);
DynCodecInfos dynInfos;
try {
dynInfos = new DynCodecInfos(ctxt, cmp);
plugins.put(cmp.flattenToString(), dynInfos);
} catch (NameNotFoundException e) {
Log.e(THIS_FILE, "Error while retrieving infos from dyn codec ", e);
}
}
}
CACHED_RESOLUTION.put(action, plugins);
}
return CACHED_RESOLUTION.get(action);
}
示例11: customReceiverPass
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Check package's MiPush custom receiver (handle com.xiaomi.mipush.RECEIVE_MESSAGE action)
* is enabled.
* @see PushMessageReceiver
* @see Constants#ACTION_RECEIVE_MESSAGE
* @param info Package info
* @return enable status. If this package not have custom receiver, will
* still returns true.
*/
private boolean customReceiverPass (PackageInfo info, PackageManager packageManager) {
//if (info.receivers == null)
// return true;
Intent intent = new Intent();
intent.setPackage(info.packageName);
//intent.setAction(Constants.ACTION_RECEIVE_MESSAGE);
for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent,
PackageManager.GET_RESOLVED_FILTER |
PackageManager.GET_DISABLED_COMPONENTS)) {
ActivityInfo activityInfo = resolveInfo.activityInfo;
if (!activityInfo.packageName.equals(info.packageName))
continue;
IntentFilter filter = resolveInfo.filter;
if (filter != null && filter.hasAction(Constants.ACTION_RECEIVE_MESSAGE)) {
boolean enabled = packageManager.getComponentEnabledSetting(new ComponentName(
activityInfo.packageName, activityInfo.name
)) == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
Log4a.i(TAG, "Handle receiver: " + activityInfo.name +
"; enabled: " + enabled);
return enabled;
}
}
Log4a.d(TAG, "Not found custom message receiver in " + info.packageName);
// Not found
return true;
}
示例12: isAddToHomeIntentSupported
import android.content.pm.PackageManager; //导入方法依赖的package包/类
/**
* Utility method to check if a shortcut can be added to the home screen.
* @param context Context used to get the package manager.
* @return if a shortcut can be added to the home screen under the current profile.
*/
// TODO(crbug.com/635567): Fix this properly.
@SuppressLint("WrongConstant")
public static boolean isAddToHomeIntentSupported(Context context) {
PackageManager pm = context.getPackageManager();
Intent i = new Intent(INSTALL_SHORTCUT);
List<ResolveInfo> receivers = pm.queryBroadcastReceivers(
i, PackageManager.GET_INTENT_FILTERS);
return !receivers.isEmpty();
}
示例13: findAndCheckReceiverInfo
import android.content.pm.PackageManager; //导入方法依赖的package包/类
private static void findAndCheckReceiverInfo(PackageManager packageManager, Intent intent,
Class<?> cls, Boolean[] boolArr) {
int i;
for (ResolveInfo resolveInfo : packageManager.queryBroadcastReceivers(intent, 16384)) {
PackageItemInfo packageItemInfo = resolveInfo.activityInfo;
if (packageItemInfo != null && cls.getCanonicalName().equals(packageItemInfo.name)) {
if (boolArr[0].booleanValue() != packageItemInfo.enabled) {
throw new a(String.format("Wrong attribute: %n <receiver " +
"android:name=\"%1$s\" .../> android:enabled should be %<b.", new
Object[]{packageItemInfo.name, boolArr[0]}), packageItemInfo);
} else if (boolArr[1].booleanValue() != packageItemInfo.exported) {
throw new a(String.format("Wrong attribute: %n <receiver " +
"android:name=\"%1$s\" .../> android:exported should be %<b.", new
Object[]{packageItemInfo.name, boolArr[1]}), packageItemInfo);
} else {
i = 1;
if (i == 0) {
throw new a(String.format("<receiver android:name=\"%1$s\" /> is missing " +
"or disabled.", new Object[]{cls.getCanonicalName()}), null);
}
}
}
}
i = 0;
if (i == 0) {
throw new a(String.format("<receiver android:name=\"%1$s\" /> is missing or disabled" +
".", new Object[]{cls.getCanonicalName()}), null);
}
}