Java Code Examples for android.content.pm.PackageManager.queryBroadcastReceivers()

The following are Jave code examples for showing how to use queryBroadcastReceivers() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: LaunchEnr   File: Utilities.java   View Source Code Vote up 7 votes
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;
}
 
Example 2
Project: CSipSimple   File: RewriterPlugin.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 3
Project: CSipSimple   File: CallHandlerPlugin.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 4
Project: CSipSimple   File: Theme.java   View Source Code Vote up 6 votes
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;
}
 
Example 5
Project: MiPushFramework   File: CheckAppSupportActivity.java   View Source Code Vote up 6 votes
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;
}
 
Example 6
Project: letv   File: a.java   View Source Code Vote up 6 votes
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;
}
 
Example 7
Project: OpenYOLO-Android   File: QueryUtil.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 8
Project: FlickLauncher   File: Utilities.java   View Source Code Vote up 6 votes
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;
}
 
Example 9
Project: SetupWizardLibCompat   File: Partner.java   View Source Code Vote up 6 votes
/**
 * 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;
}
 
Example 10
Project: SimpleUILauncher   File: Utilities.java   View Source Code Vote up 6 votes
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;
}
 
Example 11
Project: CSipSimple   File: ExtraPlugins.java   View Source Code Vote up 5 votes
/**
 * 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);
}
 
Example 12
Project: MiPushFramework   File: CheckSupportUtils.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 13
Project: chromium-for-android-56-debug-video   File: ShortcutHelper.java   View Source Code Vote up 5 votes
/**
 * 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();
}
 
Example 14
Project: boohee_v5.6   File: MiPushClient.java   View Source Code Vote up 5 votes
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);
    }
}