Home » Android » How to launch an Android app without "android.intent.category.LAUNCHER"

How to launch an Android app without "android.intent.category.LAUNCHER"

Posted by: admin June 15, 2020 Leave a comment

Questions:

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?

How to&Answers:

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.

Answer:

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

Answer:

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

Answer:

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);
         }
        });