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

    }

}

How can I 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. That's why I want to know how to hide an application.

halfer
  • 19,824
  • 17
  • 99
  • 186
Lakhwinder Singh
  • 6,799
  • 4
  • 25
  • 42
  • Refer this http://stackoverflow.com/questions/6556086/hide-the-application-in-application-manager-in-android – Devu Soman Mar 28 '13 at 10:57
  • actually i do not want to hide my application alone , i want to hide all applications that are selected by the user in my application,in which all installed applications will display. – Lakhwinder Singh Mar 28 '13 at 12:16
  • i am using the setApplicationEnabledSetting instead of setComponentEnabledSetting and my application is trying hide but tha "java.lang.SecurityException: Permission Denial: attempt to change component state from " error occurs now can yu tell me how to get these things done.Also i got the permissions of all installed applications . if you know then please help ...thank you.. – warlock just now edit – Lakhwinder Singh Mar 29 '13 at 09:17
  • possible duplicate of [Hide application icon](http://stackoverflow.com/questions/8398514/hide-application-icon) – Peter O. Apr 02 '13 at 04:36

2 Answers2

0

You can use the following to hide the app:

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);

Keep in mind that this also disables the app, so it will not respond to any more intents etc. If you want the app to remain enabled, you will have to write your own home screen and allow the user to hide icons. When the user hides an icon, you can make your launcher stop displaying it in the list.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • Thnx for reply raghav , but can you tell me how to get a component name of a application – Lakhwinder Singh Mar 28 '13 at 11:46
  • hello raghav , i am using the setApplicationEnabledSetting instead of setComponentEnabledSetting and my application is trying hide but tha "java.lang.SecurityException: Permission Denial: attempt to change component state from " error occurs now can yu tell me how to get these things done.Also i got the permissions of all installed applications . if you know then please help ...thank you.. – Lakhwinder Singh Mar 29 '13 at 09:16
0

Its pretty easy.

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();
}
}