views:

141

answers:

3

I defined an application which is only used from my other application. So I would like to hide the icon of this application, so that the user can't see it on the desktop of his phone (or how do you call the thing where all apps are listed?). My manifest file looks the following way:

<?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> 

I already read this question:

http://stackoverflow.com/questions/1063604/how-to-hide-an-application-icon-in-android-emulator

but if i just remove the line

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

in my manifest, the activity isn't working at all (ActivityNotFoundException in the calling activity).

Any hints how to solve this problem? I already tried android.intent.category.EMBEDDED but this doesn't work too.

In the Internet I found CommonsWare answer http://osdir.com/ml/Android-Developers/2010-06/msg03617.html that it can be done using PackageManager. Unfortunately, it isn't explained how exactly and I couldn't find a solution by browsing the PackageManager API.

A: 

why would you write an actual (executable) second application that merely exists to do something when it receives sth from another app?

i'd suggest, you implement this "app" as a service (remote or local). this service would then run in the background and do stuff for you and there won't be any icons to be displayed on the screen for it...

if neccessary, you can implement this service to be remote, meaning it runs in a totally different process then the first app. and: you actually can communicate via broadcast intents as you seem to do by now so you won't need to change your first app...

xenonite
this isn't possible. It is a whole game which only can be started from our p2p network. (Ok maybe it would be possible to do it in a service or whatever, but now it's too late. I just want to hide it)
Roflcoptr
A: 

You must remove the whole <intent-filter>, not just the <category>

ognian
This doesn't work too. I get an ActivityNotFoundException, because the first activity can't start the second anymore.
Roflcoptr
+1  A: 

You need to create a custom intent filter and then create an intent which uses that filter.

For example, in my Funky Expenses application external apps can add transactions. This is achieved by the manifest for Funky Expenses containing

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

and then external application can access my activity in the following way;

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

Pay special attention to the setAction call which sets the correct intent.

Al Sutton
Sorry but have you read my question? I can start the activity, but I want to hide the icon of the second activity.
Roflcoptr
His code does exactly that. Another alternative is to remove filters altogether and launch it directly by package and class name.
alexanderblom
Sebi; My code is a complete example for others. I've included the filter -and- the code to start the activity. This is from a working app where the icon for the activity isn't shown and does what you asked.
Al Sutton
I do exactly the same and I have 2 icons. however but icons are from the first activity.
Roflcoptr