android 简单桌面 可搜索

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>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值