Created
October 16, 2014 12:22
-
-
Save easternHong/47b3671e940fd5b57774 to your computer and use it in GitHub Desktop.
get_package_info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
protected List<AppInfo> doInBackground(Void... params) { | |
// TODO Auto-generated method stub | |
List<AppInfo> list = new ArrayList<AppInfo>(); | |
// 获取系统所有的应用 | |
List<PackageInfo> appList = mContext.getPackageManager() | |
.getInstalledPackages(PackageManager.GET_META_DATA); | |
// 获取应用主activity | |
for (PackageInfo p : appList) { | |
// user app | |
if (!((p.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)) | |
continue; | |
AppInfo a = new AppInfo(); | |
a.appName = p.applicationInfo.loadLabel( | |
mContext.getPackageManager()).toString(); | |
a.icon = p.applicationInfo.loadIcon(mContext | |
.getPackageManager()); | |
a.packageName = p.applicationInfo.packageName; | |
list.add(a); | |
} | |
AppLogger.d("the appList: " + list.size()); | |
return list; | |
} | |
public void LauncheApp(String packageName) { | |
Intent intent = mContext.getPackageManager().getLaunchIntentForPackage( | |
packageName); | |
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | |
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | |
| Intent.FLAG_ACTIVITY_CLEAR_TOP); | |
if (intent != null) { | |
try { | |
Toast t = Toast.makeText(mContext, "app found", | |
Toast.LENGTH_SHORT); | |
t.show(); | |
startActivity(intent); | |
} catch (ActivityNotFoundException e) { | |
// TODO: handle exception | |
Toast t = Toast.makeText(mContext, "app not found", | |
Toast.LENGTH_SHORT); | |
t.show(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment