如何从Android桌面隐藏应用程序图标?

时间:2010-07-06 07:28:49

标签: android manifest

我定义了一个仅在我的其他应用程序中使用的应用程序。所以我想隐藏这个应用程序的图标,这样用户就无法在手机的桌面上看到它(或者你如何调用列出所有应用程序的东西?)。我的清单文件看起来如下:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="xyz.games.pacman.controller"
      android:versionCode="1"
      android:versionName="1.0">

      <uses-permission android:name="android.permission.BLUETOOTH"/>

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".PacmanGame"
                  android:label="@string/app_name"
                  android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="pacman.intent.action.Launch" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>

         <receiver android:name="xyz.games.pacman.network.MessageListener">
         <intent-filter>
            <action android:name="xyz.games.pacman.controller.BROADCAST" />
            </intent-filter>
         </receiver>

    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest> 

我已经读过这个问题了:

How to hide an application icon in Android emulator?

但如果我只是删除该行

<category android:name="android.intent.category.DEFAULT" />

在我的清单中,活动根本不起作用(调用活动中的ActivityNotFoundException)。

任何提示如何解决这个问题?我已经尝试过android.intent.category.EMBEDDED,但这也行不通。

在互联网上,我发现CommonsWare回答http://osdir.com/ml/Android-Developers/2010-06/msg03617.html可以使用PackageManager完成。不幸的是,没有解释如何通过浏览PackageManager API来找到解决方案。

4 个答案:

答案 0 :(得分:1)

为什么你会编写一个实际的(可执行的)第二个应用程序,当它从另一个应用程序接收某个应用程序时,该应用程序只是为了做某事?

我建议你将这个“app”实现为服务(远程或本地)。然后,这项服务将在后台运行并为您完成任务,屏幕上不会显示任何图标...

如果需要,您可以将此服务实现为远程服务,这意味着它在与第一个应用程序完全不同的过程中运行。并且:您实际上可以通过广播意图进行通信,因为您现在似乎不需要更改第一个应用程序......

答案 1 :(得分:1)

您需要创建自定义意图过滤器,然后创建使用该过滤器的意图。

例如,在我的Funky Expenses应用程序中,外部应用程序可以添加交易。这是通过包含

的Funky Expenses清单实现的
    <activity android:name="com.funkyandroid.banking.android.ExternalEntryActivity">
        <intent-filter>
            <action android:name="com.funkyandroid.action.NEW_TRANSACTION" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

然后外部应用程序可以通过以下方式访问我的活动;

Intent launchIntent = new Intent();
launchIntent.setAction("com.funkyandroid.action.NEW_TRANSACTION");
... code to set parameters to be passed to activity ...
startActivity(launchIntent);

特别注意设置正确意图的setAction调用。

答案 2 :(得分:1)

尝试删除intent-filter而不是尝试使用过滤器lounch直接启动第二个活动:

Intent second = new Intent(context, xyz.games.pacman.controller.PacmanGame.class);
startActivity(second);

答案 3 :(得分:0)

您必须删除整个<intent-filter>,而不仅仅是<category>