8

I want to know how to launch an Android app without:

android.intent.category.LAUNCHER

Here is my AndroidManifest.xml:

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

If removing line 3, the app will not be in the launcher. The question is: where and how can I launch this app in other way?

Castiblanco
  • 1,200
  • 4
  • 13
  • 32
Richard Ye
  • 191
  • 1
  • 5
  • 12
  • I am facing a similar issue. Can you please answer my que http://stackoverflow.com/questions/10383167/android-hide-application-from-the-list-of-applications-and-assign-a-short-key-fo . Thanks a lot for your help – png May 01 '12 at 06:52

4 Answers4

9

You'll need to use a BroadcastReceiver.

public class SafetyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        ActivityManager as = (ActivityManager) context
                .getSystemService(Activity.ACTIVITY_SERVICE);
        if (IsNavigationRunning(as)) {
            Intent i = new Intent(context, VoiceActivity.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);
        }
    }
}

Manifest:

<application
    android:icon="@drawable/fot"
    android:label="@string/app_name" >
    <activity
        android:name="com.Safety.VoiceActivity"
        android:launchMode="singleTop"
        android:theme="@style/Theme.CompletelyTransparentWindow" >
    </activity>
    <receiver
        android:name="com.Safety.SafetyReceiver"
        android:process=":goodprocess" >
        <intent-filter>
            <action android:name="android.provider.Telephony.SMS_RECEIVED" />
        </intent-filter>
    </receiver>
</application>

This is an example that starts when a text is received.

Sufian
  • 6,405
  • 16
  • 66
  • 120
Ryan
  • 131
  • 2
2

This would be better if you want to launch a custom activity, for example on a button press:

Button btn = (Button)findViewById(R.id.xBtn);

btn.setOnClickListener(new OnClickListener() {
@Override
            public void onClick(View v)
            {
                    Intent intent = new Intent("it.prassel.vimsmediaplayer");
                    intent.setComponent(ComponentName
                        .unflattenFromString("it.prassel.vimsmediaplayer/it.prassel.vimsmediaplayer.MainActivity"));
                    intent.addCategory("android.intent.category.LAUNCHER");
                    startActivity(intent);
             }
});

And this is the manifest associated with your custom activity:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="it.prassel.vimsmediaplayer"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />


    <uses-feature android:glEsVersion="0x00020000" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="it.prassel.vimsmediaplayer.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="it.prassel.vimsmediaplayer" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Where

Intent intent = new Intent("it.prassel.vimsmediaplayer");

corresponds to the line

<action android:name="it.prassel.vimsmediaplayer" />

And

intent.setComponent(ComponentName
                        .unflattenFromString("it.prassel.vimsmediaplayer/it.prassel.vimsmediaplayer.MainActivity"))

corresponds to the 2 lines

package="it.prassel.vimsmediaplayer"  the part before /
android:name="it.prassel.vimsmediaplayer.MainActivity" the part after /

Your custom activity will not appear neither in the Menu nor in the Recent Apps, it will be completely anonymous. Pay attention, if you wish to be the only one who can acced to your app, to give the intent-filter a meaningful name

Luigi Tiburzi
  • 4,265
  • 7
  • 32
  • 43
  • I am getting "ActivityNotFound" exception when i try to launch it from another app. Could you tell me what more needs to be added, to open the app without launcher. – Ranjan Jul 29 '20 at 06:38
0

I want to know how to launch an Android app without: android.intent.category.LAUNCHER

In Android, an Activity should be started by an Intent. Intents can start an Activity with startActivity(Intent myIntent), example:

Intent myIntent= new Intent(context, target_class.class);
                    myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    context.startActivity(myIntent);

You must replace "myIntent", "context" (usually a "this") and the "target_class" with your variables, in order for this to work. So, whenever you need your activity, call the Intent, ans the OS will resolve for the Activity

Darek Kay
  • 15,827
  • 7
  • 64
  • 61
Bonatti
  • 2,778
  • 5
  • 23
  • 42
-1

you can specify in your class. For example on clicking of a button you want to go to some activity. so just write this code:

Button btn = (Button)findViewById(R.id.xBtn);

btn.setOnClickListener(new OnClickListener() {

         public void onClick(View v) {
          Intent intnt = new Intent();
          intnt.setAction(android.intent.action.MAIN);
          intnt.setCategory(android.intent.category.LAUNCHER);
          startActivity(intnt);
         }
        });
Lavanya
  • 3,903
  • 6
  • 31
  • 57
  • 1
    In fact, I tried .removeCategory(android.intent.category.LAUNCHER); to see if it can remove the app icon from the launcher but it failed. – Richard Ye Sep 14 '11 at 10:03