简体   繁体   English

如何从我的启动器Android隐藏应用程序图标

[英]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) 我是android的新手,我从教程创建了简单启动器,我正在列表视图中显示所有应用程序appdetails(应用程序标签,图标,程序包)

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. 您可以通过PackageManager.setComponentEnabledSetting()禁用组件,这将具有将其从启动器中删除的作用。

List component names in Android: 列出Android中的组件名称:

Following is the code to get the list of activities/applications installed on Android 以下是获取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. 您可以从packageList中获取组件名称。

ComponentName : ComponentName

Identifier for a specific application component ( Activity , Service , BroadcastReceiver , or ContentProvider ) that is available. 可用的特定应用程序组件( ActivityServiceBroadcastReceiverContentProvider )的标识符。 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 在AndroidManifest.xml中设置权限

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

From Android Developers : 来自Android开发人员

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! 因此,重新启动您的设备并查看已应用的效果!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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