(PackageManager)信息类
- 类图结构
- Android.content.pm包
- ApplicationInfo
- ComponentInfo
- ActivityInfo
- ProviderInfo
- ServiceInfo
- InstrumentationInfo
- PermissionGroupInfo
- PermissionInfo
- 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();
时间: 2024-10-14 07:58:48