Android PackageManager - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android PackageManager class.

This code example shows how to use the following methods:resolveService
    static Intent validateKatanaServiceIntent(Context context, Intent intent) {
        if (intent == null) {
            return null; 
        } 
 
        ResolveInfo resolveInfo = context.getPackageManager().resolveService(intent, 0);
        if (resolveInfo == null) {
            return null; 
        } 
 
        if (!validateSignature(context, resolveInfo.serviceInfo.packageName)) {
            return null; 
        } 
 
        return intent;
    } 
 
    static Intent createProxyAuthIntent(Context context, String applicationId, List<String> permissions) {
        Intent intent = new Intent()
                .setClassName(KATANA_PACKAGE, KATANA_PROXY_AUTH_ACTIVITY)

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setDataAndType, resolveActivity
    } 
 
    // @return a ResolveInfo instance for the mime type or null if the type is 
    // not handled by any activity. 
    private ResolveInfo resolveMime(String mime) {
        Intent viewIntent = new Intent(Intent.ACTION_VIEW);
        Uri uri = Uri.fromParts("file", MP3_FILE, null);
 
        viewIntent.setDataAndType(uri, mime);
        return mContext.getPackageManager().resolveActivity(
                viewIntent, PackageManager.MATCH_DEFAULT_ONLY);
    } 
 
    // Helper method to check the media playback activity handles the given mime type. 
    // @param mime type to test for 
    private void assertMediaPlaybackActivityHandles(String mime) throws Exception {
        ResolveInfo ri = resolveMime(mime);
 
        assertNotNull(ri);
    } 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:checkSignatures, getApplicationInfo
This code example shows how to use the following methods:getApplicationInfo, getApplicationLabel
    private CharSequence getAppName(String packageName) {
        final PackageManager pm = mContext.getPackageManager();
        ApplicationInfo ai;
 
        try { 
            ai = pm.getApplicationInfo(packageName, 0);
        } catch (final NameNotFoundException e) {
            ai = null;
        } 
 
        if (ai != null) {
            return pm.getApplicationLabel(ai);
        } 
        return null; 
    } 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setType, queryIntentActivities
     * @param mimeType 
     *            the MIME type of the content (may be null) 
     * @return true if there are apps which will respond to this action/data 
     */ 
    public static boolean isIntentAvailable(Context context, String action, Uri uri, String mimeType) {
        final Intent intent = (uri != null) ? new Intent(action, uri) : new Intent(action);
        if (mimeType != null) {
            intent.setType(mimeType);
        } 
        List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent,
                PackageManager.MATCH_DEFAULT_ONLY);
        return !list.isEmpty();
    } 
 
    /** 
     * Checks whether there are applications installed which are able to handle the given 
     * action/type. 
     *  
     * @param context 
     *            the current context 
8
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getApplicationInfo
		return pContext.getPackageName();
	} 
 
	public static String getApkFilePath(final Context pContext) throws NameNotFoundException {
		final PackageManager packMgmr = pContext.getPackageManager();
		return packMgmr.getApplicationInfo(SystemUtils.getPackageName(pContext), 0).sourceDir;
	} 
 
	private static PackageInfo getPackageInfo(final Context pContext) {
		try { 
			return pContext.getPackageManager().getPackageInfo(pContext.getPackageName(), 0);
		} catch (final NameNotFoundException e) {
			Debug.e(e);
			return null; 
		} 
	} 
 
	public static boolean hasSystemFeature(final Context pContext, final String pFeature) {
		try { 
			final Method PackageManager_hasSystemFeatures = PackageManager.class.getMethod("hasSystemFeature", new Class[] { String.class });
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageInfo
    } 
 
    public static String getApplicationVersionString(Context context) {
        try { 
            PackageManager pm = context.getPackageManager();
            PackageInfo info = pm.getPackageInfo(context.getPackageName(), 0);
            return "v" + info.versionName;
        } catch (Exception e) {
            e.printStackTrace();
            return null; 
        } 
    } 
 
    public static String createDiagnosis(Activity context, Exception error) {
        StringBuilder sb = new StringBuilder();
 
        sb.append("Application version: " + getApplicationVersionString(context) + "\n");
        sb.append("Device locale: " + Locale.getDefault().toString() + "\n\n");
        sb.append("Android ID: " + getAndroidId(context, "n/a"));
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:getPackageSizeInfo
     * android.permission.GET_PACKAGE_SIZE 
     */ 
    @SmallTest 
    public void testGetPackageSize() { 
        try { 
            mPm.getPackageSizeInfo(mPkgName, null);
            fail("PackageManager.getPackageSizeInfo" +
                    "did not throw SecurityException as expected"); 
        } catch (SecurityException e) {
            // expected 
        } 
    } 
 
    /* 
     * This test verifies that PackageManger.DeleteApplicationCacheFiles enforces permission 
     * android.permission.DELETE_CACHE_FILES 
     */ 
    @SmallTest 
    public void testDeleteApplicationCacheFiles() { 
        try { 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:queryIntentActivities
     * 
     * @return whether this phone supports voiceinput 
     */ 
    public static boolean voiceInputAvailable(Context context) {
        PackageManager pm = context.getPackageManager();
        List<ResolveInfo> activities = pm.queryIntentActivities(
                new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
        return (activities.size() != 0);
    } 
 
    private VoiceRecognizer() { 
        // 
    } 
 
    private static VoiceRecognizer instance = null;
 
    public static VoiceRecognizer instantiateVoiceRecognizer(Context context, RecognizerApiListener listener, ImageButton voiceAddButton) {
        synchronized(VoiceRecognizer.class) { 
            if (instance == null)
                instance = new VoiceRecognizer();
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:setComponentEnabledSetting
	@Override 
	public void onReceive(Context context, Intent intent) {
		if(RadioPlayerService.radioAvailable(context)) {
			context.getPackageManager().setComponentEnabledSetting(new ComponentName("fm.last.android", "fm.last.android.activity.Player"), PackageManager.COMPONENT_ENABLED_STATE_DEFAULT, PackageManager.DONT_KILL_APP);
		} else { 
			context.getPackageManager().setComponentEnabledSetting(new ComponentName("fm.last.android", "fm.last.android.activity.Player"), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
		} 
	} 
 
} 
7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java

Related Android PackageManager Questions & Answers:

See Code Examples for Android PackageManager Methods: