1,写了一个简单的桌面app.可以搜索,就一个页面,比较简洁,使用RecyclerView 来完成。
代码在我的github
https://github.com/skyphone/test2015/blob/master/app/src/main/java/launcher/MainLunchActivity.java
关键代码如下:
查询手机所有app的信息
Intent intent = new Intent(Intent.ACTION_MAIN, null); intent.addCategory(Intent.CATEGORY_LAUNCHER); List<ResolveInfo> infoList = getPackageManager().queryIntentActivities(intent, 0); // List<PackageInfo> packs = getPackageManager().getInstalledPackages(0); for (int i = 0; i < infoList.size(); i++) { ResolveInfo p = infoList.get(i); Bean bean = new Bean(); bean.appName = p.loadLabel(getPackageManager()).toString(); bean.appNameLower=bean.appName.toLowerCase(); Drawable drawable = p.loadIcon(getPackageManager()); if (drawable == null) { bean.imgUrl = Resources.getSystem().getDrawable(android.R.mipmap.sym_def_app_icon); } else { bean.imgUrl = drawable; } bean.packageName = p.activityInfo.packageName; if (p.activityInfo != null) { bean.name = p.activityInfo.name; } dataList.add(bean); }
显示后,点击事件,就可以打开app了。
Intent lauch = new Intent(Intent.ACTION_MAIN); lauch.addCategory(Intent.CATEGORY_LAUNCHER); lauch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); lauch.setComponent(new ComponentName(dataList.get(position).packageName, dataList.get(position).name)); startActivity(lauch);
还有一些需要注意的是样式:
<style name="NoActionBar" parent="Theme.AppCompat.Light.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:windowTranslucentNavigation">true</item>//透明导航栏 <item name="android:windowTranslucentStatus">true</item> //透明状态栏 <item name="android:windowBackground">@color/full</item>//设置透明 <item name="android:windowShowWallpaper">true</item> //可以显示自己的壁纸 </style>