3
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;
        }

    }

}

如何从菜单中的所有应用程序中隐藏一个应用程序?如果有人想隐藏他或她将使用我的应用程序的应用程序,我只想为应用程序隐藏、安全或个人原因创建一个应用程序。这就是为什么我想知道如何隐藏应用程序。

4

2 回答 2

0

您可以使用以下方法隐藏应用程序:

PackageManager pm = getApplicationContext().getPackageManager();
pm.setComponentEnabledSetting(<component of the main Activity of the app you want to hide>, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

请记住,这也会禁用应用程序,因此它将不再响应任何意图等。如果您希望应用程序保持启用状态,您将必须编写自己的主屏幕并允许用户隐藏图标。当用户隐藏图标时,您可以使启动器停止在列表中显示它。

于 2013-03-28T10:41:10.027 回答
0

它很容易。

如果您有 Packagename(很容易获得!),您可以使用以下代码启用禁用。请注意您将需要权限,并且您不能更改其他应用程序然后您的(因为用户 ID)。

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();
}
}
于 2013-04-12T12:47:28.693 回答