android启动一个应用工具类

/**
	 * 开启一个应用程序
	 */
	private void startApk() {
		// 开启这个应用程序里面的第1个activity.
		String packname = selectedAppInfo.getPackname();
		try {
			PackageInfo packinfo = getPackageManager().getPackageInfo(packname,
					PackageManager.GET_ACTIVITIES);
			ActivityInfo[] activityinfos = packinfo.activities;
			if(activityinfos!=null&&activityinfos.length>0){
				ActivityInfo activityinfo = activityinfos[0];
				String className = activityinfo.name;
				Intent intent = new Intent();
				intent.setClassName(selectedAppInfo.getPackname(), className);
				startActivity(intent);
			}else{
				Toast.makeText(this, "无法启动应用程序!", 0).show();
			}
		} catch (Exception e) {
			e.printStackTrace();
			Toast.makeText(this, "无法启动应用程序", 0).show();
		}

	}

你可能感兴趣的:(android,启动应用)