如何隐藏安装的应用程序列表中的应用 [英] how to hide the application from the installed application list

查看:532
本文介绍了如何隐藏安装的应用程序列表中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public class MyMainActivity extends ListActivity {
    int x;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        loadApps();

    }

    private void loadApps() {
        Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
        mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);

        List<ResolveInfo> mApps = getPackageManager().queryIntentActivities(
                mainIntent, 0);

        ListView listView = getListView();
        listView.setAdapter(new AppsAdapter(this, mApps));
    }

    public class AppsAdapter extends BaseAdapter {
        private LayoutInflater inflater;
        private List<ResolveInfo> mApps;

        public AppsAdapter(Context context, List<ResolveInfo> mApps) {
            this.inflater = LayoutInflater.from(context);
            this.mApps = mApps;
        }

        class ViewHandler {
            TextView textLable;
            ImageView iconImage;
            Button buttn;

        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {
            final ViewHandler Handler;
            if (convertView == null) {
                convertView = inflater.inflate(R.layout.customlist, null);
                Handler = new ViewHandler();
                Handler.textLable = (TextView) convertView
                        .findViewById(R.id.TV);
                Handler.iconImage = (ImageView) convertView
                        .findViewById(R.id.IV);
                Handler.buttn = (Button) convertView.findViewById(R.id.buttonx);
                convertView.setTag(Handler);
            } else {
                Handler = (ViewHandler) convertView.getTag();

            }

            ResolveInfo info = this.mApps.get(position);
            Handler.iconImage.setImageDrawable(info
                    .loadIcon(getPackageManager()));

            Handler.textLable.setText(info.loadLabel(getPackageManager()));
            Handler.buttn.setOnClickListener(new OnClickListener() {
                boolean isClicked = false;

                @Override
                public void onClick(View v) {

                    if (isClicked == false) {

                        Handler.buttn.setBackgroundResource(R.drawable.locker);
                        Toast.makeText(getApplicationContext(), "" + position,
                                Toast.LENGTH_SHORT).show();
                        isClicked = true;
                    } else {
                        Handler.buttn
                                .setBackgroundResource(R.drawable.unlocked);
                        isClicked = false;
                    }

                }
            });

            return convertView;

        }

        public final int getCount() {
            return mApps.size();
        }

        public final Object getItem(int position) {
            return mApps.get(position);
        }

        public final long getItemId(int position) {
            return position;
        }

    }

}

请告诉我如何从所有从菜单中的应用隐藏应用程序,我只是想创建一个应用程序隐藏的应用程序,对其安全性或因个人原因,如果任何想要隐藏的应用程序,他或她会用我的应用程序,这就是为什么我想知道如何隐藏应用程序

please tell me how to hide an application from all the applications from the menu,i just want to create an application for application hiding ,for security or for personal reasons if any wants to hide an app he or she would use my application ,thats why i want to know how to hide an application

推荐答案

它的pretty容易。

Its pretty easy.

如果您有PACKAGENAME(很容易得到!),你可以启用以下code禁用。请小心,您将需要权限的,你不能改变其他应用程序,然后你(因为用户标识的)。

If you have the Packagename (it's easy to get!) you can enable disable with the following code. Please take care that you will need Permissions for that and you cannot change other apps then yours (because of the userid).

public void disableDrawerIcon(String component) {
try {
    PackageManager pm = _context.getApplicationContext()
        .getPackageManager();

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

    List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);
    Collections
        .sort(appList, new ResolveInfo.DisplayNameComparator(pm));
    ComponentName componentName = null;

    for (ResolveInfo temp : appList) {

    if (temp.activityInfo.packageName.equals(component)) {

        componentName = new ComponentName(component,
            temp.activityInfo.name);
    }

    }

    if (componentName != null) {
    pm.setComponentEnabledSetting(componentName,
        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
        PackageManager.DONT_KILL_APP);
    CustomLogger.log(TAG, "Icon disabled", _context);
    }
} catch (Exception e) {
    e.printStackTrace();
}
}

public void enableDrawerIcon(String component) {
try {
    PackageManager pm = _context.getApplicationContext()
        .getPackageManager();

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

    List<ResolveInfo> appList = pm.queryIntentActivities(mainIntent, 0);
    Collections
        .sort(appList, new ResolveInfo.DisplayNameComparator(pm));
    ComponentName componentName = null;

    for (ResolveInfo temp : appList) {

    if (temp.activityInfo.packageName.equals(component)) {

        componentName = new ComponentName(component,
            temp.activityInfo.name);
    }

    }

    if (componentName != null) {

    }
    pm.setComponentEnabledSetting(componentName,
        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
        PackageManager.DONT_KILL_APP);
    CustomLogger.log(TAG, "Icon enabled", _context);
} catch (Exception e) {
    e.printStackTrace();
}
}

这篇关于如何隐藏安装的应用程序列表中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆