首页 > 代码库 > PackageManager
PackageManager
(PackageManager)信息类
- 类图结构
- Android.content.pm包
- ApplicationInfo
- ComponentInfo
- ActivityInfo
- ProviderInfo
- ServiceInfo
- InstrumentationInfo
- PermissionGroupInfo
- PermissionInfo
- Android.content.pm包
- ActivityInfo
- ProviderInfo
- ServiceInfo
- PackageInfo
- ResolveInfo
- 用例
- ApplicationInfo
- ResolveInfo
- PackageInfo
- ApplicationInfo
- ResolveInfo
- PackageInfo
public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取包名PackageManager PackageInfo ApplicationInfo ActivityInfo //获取包管理器 PackageManager pm=this.getPackageManager(); //获取所有的包信息 List<PackageInfo> packageInfos=pm.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES); for (PackageInfo packageInfo : packageInfos) { //获取应用程序信息(<application>标签) ApplicationInfo applicationInfo=packageInfo.applicationInfo; //应用程序包名 Log.i("liujun", "PackageInfo包名:---"+applicationInfo.packageName); } ////////////////////////////////////////////////////////////////////// //创建意图 Intent intent=new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_LAUNCHER); //获取解析信息对象集合 List<ResolveInfo> resolveInfos=pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resolveInfos) { //获取应用程序包名 String packName=resolveInfo.activityInfo.packageName; Log.i("liujun", "ResolveInfo包名:--"+packName); } Log.i("liujun", "packageInfos长度:--"+packageInfos.size()); Log.i("liujun", "ResolveInfo长度:--"+resolveInfos.size()); /** * 结果表明packageInfos.size()会多于resolveInfos.size()的 * 这是因为PackageInfo代表的是整个系统安装的程序(包) * ResolveInfo代表的是整个系统中含有桌面快捷图标的程序 * 显然前者包含后者,且多于后者 */ } }
代码地址
http://download.csdn.net/detail/u010739551/7893685
补充
RunningTaskInfo
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); //当前运行的任务栈信息集合 List<RunningTaskInfo> rti = mActivityManager.getRunningTasks(1); RunningTaskInfo runningTaskInfo=rti.get(0); //组件名 ComponentName componentName=runningTaskInfo.topActivity; //包名 String packageNameStr=componentName.getPackageName();
PackageManager
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。