Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android support #10

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Conversation

GioPan04
Copy link

@GioPan04 GioPan04 commented Feb 12, 2021

Android support for the plugin (except batch numbers, that are not available on Android). Fixes #9

@GioPan04 GioPan04 marked this pull request as ready for review February 14, 2021 14:22
@GioPan04
Copy link
Author

@tastelessjolt I made the Android support, take a look.

@GioPan04
Copy link
Author

I also refactored the example app to make more easy to read

Comment on lines 26 to 27
IconChanger.enableIcon(context, iconName);
IconChanger.disableIcon(context, "MainActivity");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First, thanks for the contribution.
This makes only one alternative icon available.
I think we should disable all possible other icons and enable the selected icon.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, how do you think it should restore to the default icon?

The API used for restoring icon in iOS is that, passing null to setAlternateIcon(?) should restore the icon to the main/primary icon. I would like to keep the same API for Android as well.

I haven't tested the app as I don't have a PC currently.

PackageInfo info = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_ACTIVITIES | PackageManager.GET_DISABLED_COMPONENTS);
ActivityInfo enabled = null;
for(ActivityInfo activityInfo: info.activities) {
// An hard coded way to get only the app activities, only way I found :(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.android.com/reference/android/content/pm/ActivityInfo#targetActivity
Check this attribute, you can check targetActivity for null to know whether it is a activity-alias or not. And for the main activity, I don't quite know, you might find something for the MainActivity.

} else if (call.method.equals("mSetAlternateIconName")) {
result.error("Not supported", "Not supported on Android", null);
String iconName = call.argument("iconName");
if(iconName == null) iconName = "MainActivity";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MainActivity is not the default value. It is better to use getActivities first element of the array

@Nei1eveN
Copy link

@GioPan04 any update on this?

@joknjokn
Copy link

We're looking forward to this feature as well! Any news?

@akifarhan
Copy link

Any updates on this PR?

@tastelessjolt
Copy link
Owner

Sorry for the long absence
The status right now is that I have made more changes to this PR and have it ready.
But currently wherever the app icon is changed in Android, the app is closed by the system and doesn't re-open.
If anyone has an idea how to make it work without the app getting closed please share some examples on how it is done.

@giandifra
Copy link

I have same issue, I'm investigating on

@giandifra
Copy link

giandifra commented Nov 3, 2021

This the issue that I encountered:

  • There are 2 launcher icons after set an <activity-alias> (1 for MainActivity 1 for activity-alias). This because contain <category android:name="android.intent.category.LAUNCHER"/>. Removing it we will encounter this flutter issue

Following native guide to set <activity-alias> here I haven't success because this

@chuanpham
Copy link

@giandifra have you found the solution for the problem? Thanks!

@giandifra
Copy link

I didn't

@armandojimenez
Copy link

Any hope for this? 🥲

@tastelessjolt
Copy link
Owner

Any hope for this? 🥲

As long as this issue exists upstream, flutter/flutter#38965, android support won't be published
You can still try it out for yourself from this branch: https://github.com/tastelessjolt/flutter_dynamic_icon/tree/GioPan04-android-support

It's a bad user experience that you have to crash the app to change the app icon.

@remcoanker
Copy link

remcoanker commented Sep 21, 2022

I don't think it's possible without stopping the app, but we can restart, see this commit.

@rajnishsharma1
Copy link

The app will be stopped when you change the icon dynamically from app, it happens in Android Native as well.

@aiserrock
Copy link

aiserrock commented Feb 8, 2023

@tastelessjolt you can try integrating this alternative solution on activity-alias
https://github.com/gonodono/app-icon-change-demo
One restart is required, and then everything works very well without a restart.

Screen.Recording.2023-02-08.at.21.41.10.mov

@rajatsingh0406
Copy link

by using this package I am able to change the app launcher icon and able to set it to default, but after setting it to default I open the app then my app is not opening and instead of that app info page is opening

@chandrabezzo
Copy link

Have you all check other plugin flutter_dynamic_icon_plus?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android Support