Java Code Examples for android.content.pm.PackageManager#getReceiverInfo()

The following examples show how to use android.content.pm.PackageManager#getReceiverInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InputManagerService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private void visitKeyboardLayout(String keyboardLayoutDescriptor,
        KeyboardLayoutVisitor visitor) {
    KeyboardLayoutDescriptor d = KeyboardLayoutDescriptor.parse(keyboardLayoutDescriptor);
    if (d != null) {
        final PackageManager pm = mContext.getPackageManager();
        try {
            ActivityInfo receiver = pm.getReceiverInfo(
                    new ComponentName(d.packageName, d.receiverName),
                    PackageManager.GET_META_DATA
                            | PackageManager.MATCH_DIRECT_BOOT_AWARE
                            | PackageManager.MATCH_DIRECT_BOOT_UNAWARE);
            visitKeyboardLayoutsInPackage(pm, receiver, d.keyboardLayoutName, 0, visitor);
        } catch (NameNotFoundException ex) {
        }
    }
}
 
Example 2
Source File: ExtraPlugins.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Build codec infos based on a component name of a manifest
 * It will retrieve {@link SipManager#META_LIB_NAME} and {@link SipManager#META_LIB_INIT_FACTORY} from the meta datas of the component
 * @param ctxt The current application context
 * @param cmp The component name of the remote plugin application
 * @throws NameNotFoundException If the remote component is not found
 */
public DynCodecInfos(Context ctxt, ComponentName cmp) throws NameNotFoundException {
	PackageManager pm = ctxt.getPackageManager();
	ActivityInfo infos = pm.getReceiverInfo(cmp, PackageManager.GET_META_DATA);
	factoryInitFunction = infos.metaData.getString(SipManager.META_LIB_INIT_FACTORY);
          factoryDeinitFunction = infos.metaData.getString(SipManager.META_LIB_DEINIT_FACTORY);
	
	String libName = infos.metaData.getString(SipManager.META_LIB_NAME);
	
	PackageInfo pInfos = pm.getPackageInfo(cmp.getPackageName(), PackageManager.GET_SHARED_LIBRARY_FILES);
	// TODO : for now only api-9 compatible
	File libFile = NativeLibManager.getLibFileFromPackage(pInfos.applicationInfo, libName, true);
	if(libFile != null) {
		libraryPath = libFile.getAbsolutePath(); 
	}
}
 
Example 3
Source File: AmazonBillingProvider.java    From OPFIab with Apache License 2.0 6 votes vote down vote up
@SuppressFBWarnings({"EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"})
@Override
public void checkManifest() {
    OPFChecks.checkPermission(context, ACCESS_NETWORK_STATE);
    //TODO OPFCheck.checkReceiver
    final PackageManager packageManager = context.getPackageManager();
    final ComponentName componentName = new ComponentName(context, ResponseReceiver.class);
    try {
        if (!packageManager.getReceiverInfo(componentName, 0).exported) {
            throw new IllegalStateException("Amazon receiver must be exported.");
        }
    } catch (PackageManager.NameNotFoundException exception) {
        throw new IllegalStateException(
                "You must declare Amazon receiver to use Amazon billing provider.", exception);
    }
}
 
Example 4
Source File: MetaDataUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Return the value of meta-data in receiver.
 *
 * @param clz The receiver class.
 * @param key The key of meta-data.
 * @return the value of meta-data in receiver
 */
public static String getMetaDataInReceiver(@NonNull final Class<? extends BroadcastReceiver> clz,
                                           @NonNull final String key) {
    String value = "";
    PackageManager pm = Utils.getApp().getPackageManager();
    ComponentName componentName = new ComponentName(Utils.getApp(), clz);
    try {
        ActivityInfo info = pm.getReceiverInfo(componentName, PackageManager.GET_META_DATA);
        value = String.valueOf(info.metaData.get(key));
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    return value;
}
 
Example 5
Source File: SetupViewModel.java    From island with Apache License 2.0 5 votes vote down vote up
private static CharSequence readOwnerLabel(final Context context, final ComponentName owner) {
	final PackageManager pm = context.getPackageManager();
	try {
		final ActivityInfo owner_info = pm.getReceiverInfo(owner, 0);	// It should be a BroadcastReceiver
		if (owner_info != null) return owner_info.loadLabel(pm);
		return pm.getApplicationInfo(owner.getPackageName(), 0).loadLabel(pm);	// If not, use app label
	} catch (final PackageManager.NameNotFoundException ignored) {
		return null;
	}
}
 
Example 6
Source File: DevicePluginXmlUtil.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * コンポーネントのActivityInfoを取得する.
 *
 * @param context コンテキスト
 * @param packageName package name
 * @return コンポーネントのActivityInfo
 */
private static ActivityInfo getReceiverInfo(final Context context, final String packageName) {
    try {
        PackageManager pkgMgr = context.getPackageManager();
        PackageInfo pkg = pkgMgr.getPackageInfo(packageName, PackageManager.GET_RECEIVERS);
        if (pkg != null) {
            ActivityInfo[] receivers = pkg.receivers;
            if (receivers != null) {
                for (int i = 0; i < receivers.length; i++) {
                    String pkgName = receivers[i].packageName;
                    String className = receivers[i].name;
                    ComponentName component = new ComponentName(pkgName, className);
                    ActivityInfo receiverInfo = pkgMgr.getReceiverInfo(component, PackageManager.GET_META_DATA);
                    if (receiverInfo.metaData != null) {
                        Object xmlData = receiverInfo.metaData.get(PLUGIN_META_DATA);
                        if (xmlData instanceof Integer) {
                            XmlResourceParser xrp = receiverInfo.loadXmlMetaData(pkgMgr, PLUGIN_META_DATA);
                            if (xrp != null) {
                                return receiverInfo;
                            }
                        }
                    }
                }
            }
        }
        return null;
    } catch (NameNotFoundException e) {
        return null;
    }
}
 
Example 7
Source File: DevicePluginManager.java    From DeviceConnect-Android with MIT License 3 votes vote down vote up
/**
 * 指定されたコンポーネントの ReceiverInfo を取得します.
 * <p>
 * 一致する ReceiverInfo が存在しない場合は null を返却します。
 * </p>
 * @param pkgMgr パッケージマネージャ
 * @param component コンポーネント
 * @return ReceiverInfoのインスタンス
 */
private ActivityInfo getReceiverInfo(final PackageManager pkgMgr, final ComponentName component) {
    try {
        return pkgMgr.getReceiverInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        return null;
    }
}