App not showing in “Apps” in simulator
-
21-12-2019 - |
Question
I have an app with the below intent in my manifest:
<activity
android:name=".ui.ui.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="myapp.com" android:scheme="http" />
</intent-filter>
</activity>
When I run the app from my IDE, it shows up on the simulator. However, it does not have an icon in the "Apps". So if I need to launch it again, I have to run the app again from my IDE.
If I change the Intent to just:
<activity
android:name=".ui.ui.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN">
<category android:name="android.intent.category.LAUNCHER">
</intent-filter>
</activity>
then it does get an icon in the "Apps" however, now I lose the other features i need - like browsable
and data
Question
How can I keep the original intent and still have an icon for the app in "Apps" section?
Solution
You should split the different actions into their own filter.
<activity
android:name=".ui.ui.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="myapp.com" android:scheme="http" />
</intent-filter>
</activity>
In your activity you can respond differently to the different actions.
Intent intent = getIntent();
// To get the action of the intent use
String action = intent.getAction();
if (action.equals(Intent.ACTION_VIEW)) {
//Do something
} else if(action.equals(Intent.ACTION_MAIN) {
//Do something else...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow