根据包名启动安卓应用方法

根据包名启动安卓应用方法
方法一:
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage(
packageName);
startActivity(LaunchIntent);

方法二:
/**
* 根据指定的包名,启动应用
* @param packageName
* @return
*/
public static ComponentName getComponent(Context context,String packageName)
{
ComponentName pn = null;
List<ResolveInfo> matches = findActivitiesForPackage(
context, packageName);
if ((matches != null) && (matches.size() > 0))
{
ResolveInfo resolveInfo = matches.get(0);
ActivityInfo activityInfo = resolveInfo.activityInfo;
//return startApk(activityInfo.packageName, activityInfo.name);
pn = new ComponentName(packageName,activityInfo.name);
}
return pn;
}
public static List<ResolveInfo> findActivitiesForPackage(Context context,
String packageName)
{
final PackageManager pm = context.getPackageManager();

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mainIntent.setPackage(packageName);

final List<ResolveInfo> apps = pm.queryIntentActivities(mainIntent, 0);
return apps != null ? apps : new ArrayList<ResolveInfo>();
}
更多内容: 江南烟雨QQ空间_江南烟雨_程序员_java_c/c++http://172042886.qzone.qq.com

你可能感兴趣的:(根据包名启动安卓应用方法)