通过包名启动程序
之前在启动外部程序都是通过包名和类名来启动,如下:
Intent intent = new Intent();intent.setClassName(packageName, activityName);startActivity(intent);
现在又发现了另一种只要通过包名就可以启动的方法,支持1.5及以上:
Intent intent =getPackageManager().getLaunchIntentForPackage(packageName);startActivity(intent);
public abstract Intent getLaunchIntentForPackage(String packageName)
Since: API Level 3
api解释如下:
Return a "good" intent to launch a front-door activity in a package, for use for example to implement an "open" button when browsing through packages. The current implementation will look first for a main activity in the category CATEGORY_INFO, next for a main activity in the category CATEGORY_LAUNCHER, or return null if neither are found. Throws PackageManager.NameNotFoundException if a package with the given name can not be found on the system.