final PackageManager pm = context.getPackageManager();
//get a list of installed apps.
List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);
for (ApplicationInfo packageInfo : packages) {
String packagename = ((String) packageInfo.loadLabel(pm)).replaceAll(" ", "").toLowerCase();
if(packagename.contains(appname)){
say("Opening"+appname);
Intent launchIntent = pm.getLaunchIntentForPackage(packageInfo.packageName);
Log.v(TAG, ""+launchIntent);
context.startActivity(launchIntent);
}
使用此代码,我的应用程序在打开消息传递时关闭,并且只关闭消息传递。它确实打开了消息传递应用程序,但强制关闭并引发空指针异常。有任何想法吗?
多谢你们!