3

I would like to hide my android app from the launcher, but be able to call it from within another app. I am lost on what to remove from the android manifest.

Already tried removing...

<intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>

...but then it doesn't open when called from another app.

Here is what how I am calling this hidden

        Intent i;
            PackageManager manager = getPackageManager();
            try {
                i = manager.getLaunchIntentForPackage("org.xbmc.xbmc");
                if (i == null)
                    throw new PackageManager.NameNotFoundException();
                i.addCategory(Intent.CATEGORY_LAUNCHER);
                startActivity(i);

            } catch (PackageManager.NameNotFoundException e) {

Here is the top of the manifest

  xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:hasCode="true" android:debuggable="true">
    <activity android:theme="@*android:style/Theme.NoTitleBar.Fullscreen" android:name=".Splash" android:finishOnTaskLaunch="true" android:launchMode="singleInstance" android:screenOrientation="sensorLandscape" android:configChanges="touchscreen|keyboard|keyboardHidden|navigation|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>                
cre8ful
  • 43
  • 1
  • 1
  • 5

2 Answers2

13

You need to remove the following line from your AndroidManifest.xml:

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

This will remove the application from the default launcher. However, you also need to add the following line such that your BroadcastReceiver is not completely ignored:

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

You should NOT remove the line below - it is used to specify which Activity should launch first when your app is opened:

<action android:name="android.intent.action.MAIN"/>

EDIT

In order to launch the application discussed above from another application, you cannot use the calls shown in your question. You are trying to open the application by creating an Intent with the CATEGORY_LAUNCHER tag (i.addCategory(Intent.CATEGORY_LAUNCHER)) when you have explicitly removed the following line from your AndroidManifest.xml file:

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

The absence of the above line means that the application you are trying to call will ignore the launch Intent. In order to launch your application you will need to act upon another Intent. Here is an example that shows how to open an application, which doesn't contain a launch intent filter, by responding to a SMS Intent: How to launch an Android app without "android.intent.category.LAUNCHER"

Which intent you choose to use is up to you - just make sure you add it to your AndroidManifest.xml file.

Community
  • 1
  • 1
Willis
  • 5,308
  • 3
  • 32
  • 61
0

Try this code:

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

and check this link.

hope this helps.

Community
  • 1
  • 1
user 12321
  • 2,846
  • 1
  • 24
  • 34