简体   繁体   中英

How To hide application icon from my launcher android

I m newbie in android i created Simple launcher from Tutorial i am showing all app in listview appdetails(app lable ,icon,package)

I want Hide app Icon Which I Want ..

i am trying To Hide but I am Unable To Understande How To Getcomponent Name Of Other application

private void addClickListener() {
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> av, View v, int pos,
                long id) {

            ComponentName componentName = new ComponentName(apps.get(pos).name.toString());, apps.get(pos).name.toString());.LauncherActivity);
         manager.setComponentEnabledSetting(componentName, PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            /*Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());
            AppsListActivity.this.startActivity(i);*/
        }
    });

here is code Which I Tried but Not Working

plzz tell me what i am doing wrong and what should i do

please thanx advance

EDit

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ah.hathi.simplelauncher"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="20" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

<activity
android:name="ah.hathi.simplelauncher.HomeActivity"
android:label="Simple Launcher Home"
android:theme="@android:style/Theme.Wallpaper.NoTitleBar.Fullscreen"
android:launchMode="singleTask"
android:stateNotNeeded="true"
>
<intent-filter>
  <action android:name="android.intent.action.MAIN" />
  <category android:name="android.intent.category.HOME" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>         

<activity
android:name="ah.hathi.simplelauncher.AppsListActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
>            

You can disable a component via PackageManager.setComponentEnabledSetting() , which will have the effect of removing it from the Launcher.

List component names in Android:

Following is the code to get the list of activities/applications installed on Android

final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
final List packageList = context.getPackageManager().queryIntentActivities( mainIntent, 0);

You can get the component names from packageList.

ComponentName :

Identifier for a specific application component ( Activity , Service , BroadcastReceiver , or ContentProvider ) that is available. Two pieces of information, encapsulated here, are required to identify a component: the package (a String) it exists in, and the class (a String) name inside of that package.

set permission in AndroidManifest.xml

<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE>

From Android Developers :

Allows an application to change whether an application component (other than its own) is enabled or not.

Note: Not for use by third-party applications.

Try this Code:

PackageManager p = getPackageManager();
p.setComponentEnabledSetting(getComponentName(), PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);

Or try this:

PackageManager pm = this.getPackageManager();
pm.setComponentEnabledSetting(new ComponentName("com.google.android.talk",
    "com.google.android.talk.LAUNCHER"),
    PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
    PackageManager.DONT_KILL_APP);

Note: The icon may not be gone until the next reboot. So reboot your device and see the applied effect!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM