Tutorial :How to hide application icon from the Android Desktop?



Question:

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:

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.


Solution:1

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.


Solution:2

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


Solution:3

Try removing the intent-filter and instead of trying to launch the 2nd activity with the filter lounch directly the activity:

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


Solution:4

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »