app-icon
app-icon copied to clipboard
feat(android): PoC for Android
I started with a PoC for an Android implementation. As its a bit differently used, we are not able to pass an icon path.
Therefore, I changed the config of the icon as following (it's a proposal, happy for comments ;) ):
{
"appId": "com.my.app",
"plugins": {
"AppIcon": {
"icons": {
"layout1": {
"androidActivity": "com.my.app.MainActivity.MainActivityLayout1",
"iosIconName": "layout1-icon"
},
"layout2": {
"androidActivity": "com.my.app.MainActivity.MainActivityLayout2",
"iosIconName": "layout2-icon"
}
}
}
Android then needs a very specific AndroidManifest.xml!
The main activity should not have a launcher and for every icon, an activity-alias entry is needed (whereas the first one is set to android:enabled="true", which marks the default icon:
<manifest ... >
<application ... >
<activity ...
android:name="com.my.app.MainActivity"
android:label="My App"
android:theme="@style/AppTheme.NoActionBarLaunch"
android:launchMode="singleTask"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!--<category android:name="android.intent.category.LAUNCHER" />-->
</intent-filter>
<!-- alternative activities for separate icons -->
<activity-alias
android:name="com.my.app.MainActivity.MainActivityLayout1"
android:enabled="true"
android:icon="@mipmap/ic_launcher_layout1"
android:roundIcon="@mipmap/ic_launcher_round_layout1"
android:label="My App"
android:targetActivity=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- ??? every intent filter needed? -->
</activity-alias>
<activity-alias
android:name="com.my.app.MainActivity.MainActivityLayout2"
android:enabled="false"
android:icon="@mipmap/ic_launcher_layout2"
android:roundIcon="@mipmap/ic_launcher_round_layout2"
android:label="My App"
android:targetActivity=".MainActivity"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- ??? every intent filter needed? -->
</activity-alias>
</activity>
</application>
BUT there are some issues:
- On Android 10, the app closes completely when an activity is disabled! One workaround discussed in the community is, changing the icon once the app closes (but until then, the user would have two icons!).
- All intent-filters e.g. for deeplinks would need to be added to every
activity-alias!!
@johnborges what do you think? Did you struggle with the same issues or did you have an alternative approach?
@chvonrohr thanks for sharing! Yes, the biggest issues I ran into were the stability problems you mentioned. The Android APIs in PackageManager for app icon switching seem unstable at times. I ran into random app crashes a lot.
I'm looking over your AppIcon.java methods. Might be able to use some of them.
@chvonrohr Can you include the example app where you have this plugin implemented. I'de like to see the config options and full AndroidManifest.xml
@all-contributors please add @chvonrohr for code