您的位置:首页 > 移动开发

取得Android系统全部app

2011-05-07 21:15 239 查看
PackageManager pm = ctx.getApplicationContext().getPackageManager();
appList = pm.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
--------------------------------------------
Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
mApps = getPackageManager().queryIntentActivities(mainIntent, 0);

--------------------------------------------

//下面是android2.2 Launcher源代码的LauncherModel用到的代码

final Intent mainIntent = new Intent( Intent.ACTION_MAIN, null );
mainIntent.addCategory( Intent.CATEGORY_LAUNCHER );

final PackageManager packageManager = mContext.getPackageManager();
List<ResolveInfo> apps = null;
//获取系统全部的应用程序
//在指定的intent中获取所有可能执行的activity列表
apps = packageManager.queryIntentActivities( mainIntent, 0 );
//APP总数
int N = apps.size();

-------------------------------------------------------------------------------------------------------------------------------------------------

‍ 在Activity里操作:

Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

PackageManager mPackageManager = getPackageManager();
//符合上面条件的全部查出来,并且排序
List<ResolveInfo> mAllApps = mPackageManager.queryIntentActivities(mainIntent, 0);
Collections.sort(mAllApps, new ResolveInfo.DisplayNameComparator(mPackageManager));

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android null