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

The following are Jave code examples for showing how to use getActivityInfo() 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: kognitivo   File: Validate.java   View Source Code Vote up 6 votes
public static void hasFacebookActivity(Context context, boolean shouldThrow) {
    Validate.notNull(context, "context");
    PackageManager pm = context.getPackageManager();
    ActivityInfo activityInfo = null;
    if (pm != null) {
        ComponentName componentName =
                new ComponentName(context, FacebookActivity.class);
        try {
            activityInfo = pm.getActivityInfo(componentName, PackageManager.GET_ACTIVITIES);
        } catch (PackageManager.NameNotFoundException e) {
        }
    }
    if (activityInfo == null) {
        if (shouldThrow) {
            throw new IllegalStateException(FACEBOOK_ACTIVITY_NOT_FOUND_REASON);
        } else {
            Log.w(TAG, FACEBOOK_ACTIVITY_NOT_FOUND_REASON);
        }
    }
}
 
Example 2
Project: CSipSimple   File: SuggestionsAdapter.java   View Source Code Vote up 6 votes
/**
 * Gets the activity or application icon for an activity.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the acitivy or the application
 *         have an icon set.
 */
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = mContext.getPackageManager();
    final ActivityInfo activityInfo;
    try {
        activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
    int iconId = activityInfo.getIconResource();
    if (iconId == 0) return null;
    String pkg = component.getPackageName();
    Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
    if (drawable == null) {
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for "
                + component.flattenToShortString());
        return null;
    }
    return drawable;
}
 
Example 3
Project: letv   File: QQAuth.java   View Source Code Vote up 6 votes
public static QQAuth createInstance(String str, Context context) {
    Global.setContext(context.getApplicationContext());
    f.c(f.d, "QQAuth -- createInstance() --start");
    try {
        PackageManager packageManager = context.getPackageManager();
        packageManager.getActivityInfo(new ComponentName(context.getPackageName(), "com.tencent.tauth.AuthActivity"), 0);
        packageManager.getActivityInfo(new ComponentName(context.getPackageName(), "com.tencent.connect.common.AssistActivity"), 0);
        QQAuth qQAuth = new QQAuth(str, context);
        f.c(f.d, "QQAuth -- createInstance()  --end");
        return qQAuth;
    } catch (Throwable e) {
        f.b(f.d, "createInstance() error --end", e);
        Toast.makeText(context.getApplicationContext(), "请参照文档在Androidmanifest.xml加上AuthActivity和AssitActivity的定义 ", 1).show();
        return null;
    }
}
 
Example 4
Project: boohee_v5.6   File: QQAuth.java   View Source Code Vote up 6 votes
public static QQAuth createInstance(String str, Context context) {
    Global.setContext(context.getApplicationContext());
    f.c(f.d, "QQAuth -- createInstance() --start");
    try {
        PackageManager packageManager = context.getPackageManager();
        packageManager.getActivityInfo(new ComponentName(context.getPackageName(), "com" +
                ".tencent.tauth.AuthActivity"), 0);
        packageManager.getActivityInfo(new ComponentName(context.getPackageName(), "com" +
                ".tencent.connect.common.AssistActivity"), 0);
        QQAuth qQAuth = new QQAuth(str, context);
        f.c(f.d, "QQAuth -- createInstance()  --end");
        return qQAuth;
    } catch (Throwable e) {
        f.b(f.d, "createInstance() error --end", e);
        Toast.makeText(context.getApplicationContext(), "请参照文档在Androidmanifest" +
                ".xml加上AuthActivity和AssitActivity的定义 ", 1).show();
        return null;
    }
}
 
Example 5
Project: boohee_v5.6   File: SuggestionsAdapter.java   View Source Code Vote up 6 votes
private Drawable getActivityIcon(ComponentName component) {
    PackageManager pm = this.mContext.getPackageManager();
    try {
        ActivityInfo activityInfo = pm.getActivityInfo(component, 128);
        int iconId = activityInfo.getIconResource();
        if (iconId == 0) {
            return null;
        }
        Drawable drawable = pm.getDrawable(component.getPackageName(), iconId, activityInfo.applicationInfo);
        if (drawable != null) {
            return drawable;
        }
        Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
        return null;
    } catch (NameNotFoundException ex) {
        Log.w(LOG_TAG, ex.toString());
        return null;
    }
}
 
Example 6
Project: SimpleUILauncher   File: InstallShortcutReceiver.java   View Source Code Vote up 6 votes
/**
 * Ensures that we have a valid, non-null name.  If the provided name is null, we will return
 * the application name instead.
 */
@Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) {
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException nnfe) {
            return "";
        }
    }
    return name;
}
 
Example 7
Project: LaunchEnr   File: InstallShortcutReceiver.java   View Source Code Vote up 5 votes
/**
 * Ensures that we have a valid, non-null name.  If the provided name is null, we will return
 * the application name instead.
 */
@Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) {
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException nnfe) {
            return "";
        }
    }
    return name;
}
 
Example 8
Project: CSipSimple   File: GlowPadView.java   View Source Code Vote up 5 votes
/**
 * Searches the given package for a resource to use to replace the Drawable on the
 * target with the given resource id
 * @param component of the .apk that contains the resource
 * @param name of the metadata in the .apk
 * @param existingResId the resource id of the target to search for
 * @return true if found in the given package and replaced at least one target Drawables
 */
public boolean replaceTargetDrawablesIfPresent(ComponentName component, String name,
            int existingResId) {
    if (existingResId == 0) return false;

    boolean replaced = false;
    if (component != null) {
        try {
            PackageManager packageManager = getContext().getPackageManager();
            // Look for the search icon specified in the activity meta-data
            Bundle metaData = packageManager.getActivityInfo(
                    component, PackageManager.GET_META_DATA).metaData;
            if (metaData != null) {
                int iconResId = metaData.getInt(name);
                if (iconResId != 0) {
                    Resources res = packageManager.getResourcesForActivity(component);
                    replaced = replaceTargetDrawables(res, existingResId, iconResId);
                }
            }
        } catch (NameNotFoundException e) {
            Log.w(THIS_FILE, "Failed to swap drawable; "
                    + component.flattenToShortString() + " not found", e);
        } catch (Resources.NotFoundException nfe) {
            Log.w(THIS_FILE, "Failed to swap drawable from "
                    + component.flattenToShortString(), nfe);
        }
    }
    if (!replaced) {
        // Restore the original drawable
        replaceTargetDrawables(getContext().getResources(), existingResId, existingResId);
    }
    return replaced;
}
 
Example 9
Project: easyfilemanager   File: PackageManagerUtils.java   View Source Code Vote up 5 votes
public static ComponentName getComponentName(Context context, Intent intent) {
	PackageManager packageManager = context.getPackageManager();
	ComponentName resolvedComponentName = intent.resolveActivity(packageManager);
	try {
		ActivityInfo activityInfo = packageManager.getActivityInfo(resolvedComponentName, 0);
		if (activityInfo.targetActivity != null) {
			return new ComponentName(resolvedComponentName.getPackageName(), activityInfo.targetActivity);
		}
	} catch (PackageManager.NameNotFoundException e) {
		// TODO nothing
	}
	return resolvedComponentName;
}
 
Example 10
Project: RxEasyHttp   File: AppTools.java   View Source Code Vote up 5 votes
private static ActivityInfo getActivityInfo(Activity context) {
    PackageManager packageManager = context.getPackageManager();
    try {
        return packageManager.getActivityInfo(context.getComponentName(),
                PackageManager.GET_META_DATA);
    } catch (NameNotFoundException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 11
Project: FireFiles   File: PackageManagerUtils.java   View Source Code Vote up 5 votes
public static ComponentName getComponentName(Context context, Intent intent) {
	PackageManager packageManager = context.getPackageManager();
	ComponentName resolvedComponentName = intent.resolveActivity(packageManager);
	try {
		ActivityInfo activityInfo = packageManager.getActivityInfo(resolvedComponentName, 0);
		if (activityInfo.targetActivity != null) {
			return new ComponentName(resolvedComponentName.getPackageName(), activityInfo.targetActivity);
		}
	} catch (PackageManager.NameNotFoundException e) {
		// TODO nothing
	}
	return resolvedComponentName;
}
 
Example 12
Project: minu-poska-android   File: BaseActivity.java   View Source Code Vote up 5 votes
protected String title() {
    try {
        PackageManager pm = getPackageManager();
        ActivityInfo activityInfo = pm.getActivityInfo(getComponentName(), 0);
        if (activityInfo.labelRes != 0) {
            return getString(activityInfo.labelRes);
        }
    } catch (PackageManager.NameNotFoundException e) {
        Log.e(TAG, "Failed to find package manager", e);
    }
    return getString(R.string.app_name);
}
 
Example 13
Project: simple-share-android   File: PackageManagerUtils.java   View Source Code Vote up 5 votes
public static ComponentName getComponentName(Context context, Intent intent) {
	PackageManager packageManager = context.getPackageManager();
	ComponentName resolvedComponentName = intent.resolveActivity(packageManager);
	try {
		ActivityInfo activityInfo = packageManager.getActivityInfo(resolvedComponentName, 0);
		if (activityInfo.targetActivity != null) {
			return new ComponentName(resolvedComponentName.getPackageName(), activityInfo.targetActivity);
		}
	} catch (PackageManager.NameNotFoundException e) {
		// TODO nothing
	}
	return resolvedComponentName;
}
 
Example 14
Project: FlickLauncher   File: InstallShortcutReceiver.java   View Source Code Vote up 5 votes
/**
 * Ensures that we have a valid, non-null name.  If the provided name is null, we will return
 * the application name instead.
 */
@Thunk static CharSequence ensureValidName(Context context, Intent intent, CharSequence name) {
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm);
        } catch (PackageManager.NameNotFoundException nnfe) {
            return "";
        }
    }
    return name;
}
 
Example 15
Project: ModuleFrame   File: AppUtil.java   View Source Code Vote up 5 votes
/**
 * 获取Activity中的meta-data.
 *
 * @param packageManager 应用管理
 * @param component 组件
 * @return
 */
public static Bundle getActivityMetaDataBundle(PackageManager packageManager, ComponentName component) {
    Bundle bundle = null;
    try {
        ActivityInfo ai = packageManager.getActivityInfo(component,
                PackageManager.GET_META_DATA);
        bundle = ai.metaData;
    } catch (PackageManager.NameNotFoundException e) {
        LogUtil.logE(AppUtil.class, Log.getStackTraceString(e));
    }
    return bundle;
}
 
Example 16
Project: PaletteGetter   File: PaletteGetter.java   View Source Code Vote up 4 votes
@Nullable
@ColorInt
public static Integer get(Context context, ComponentName componentName) {
    PackageManager packageManager = context.getPackageManager();

    ActivityInfo activityInfo = null;
    PackageInfo packageInfo = null;
    Resources resources = null, activityResources = null;
    try {
        packageInfo = packageManager.getPackageInfo(componentName.getPackageName(), PackageManager.GET_META_DATA);
        resources = packageManager.getResourcesForApplication(packageInfo.applicationInfo);
        activityInfo = packageManager.getActivityInfo(componentName, 0);
        activityResources = packageManager.getResourcesForActivity(componentName);
    } catch (PackageManager.NameNotFoundException ignored) {
    }

    if (packageInfo != null && resources != null) {
        if (activityInfo != null && activityResources != null) {
            List<Integer> activityStatusBarColors = getResourceColors(activityInfo.packageName, resources, activityInfo.theme);
            if (activityStatusBarColors.size() > 0) {
                return activityStatusBarColors.get(0);
            }
        }

        List<Integer> statusBarColors = getResourceColors(packageInfo.packageName, resources, packageInfo.applicationInfo.theme);
        if (statusBarColors.size() > 0) {
            return statusBarColors.get(0);
        }

        if (packageInfo.activities != null) {
            for (ActivityInfo otherActivityInfo : packageInfo.activities) {
                List<Integer> otherStatusBarColors = getResourceColors(packageInfo.packageName, resources, otherActivityInfo.theme);
                if (otherStatusBarColors.size() > 0) {
                    return otherStatusBarColors.get(0);
                }
            }
        }
    }

    return null;
}