首先搜索手机文件是一个耗时的操作,所以要在子线程里面来执行
new Thread() {
public void run() {
mList = AppInfoProvide.getAppAllInfo(getActivity().getApplicationContext());
for (AppInfo info : mList) {
if (info.getAppName().equals("APP的名字")) {
startApp(info);//启动App的方法
}
}
}
}.start();
启动App的方法:
public void startApp(AppInfo info) {
PackageManager pm = getActivity().getPackageManager();
Intent intent = pm.getLaunchIntentForPackage(info.getPackName());
if (intent != null) {
//说明是可以被启动
startActivity(intent);
}
}