Code Monkey home page Code Monkey logo

flutter_live_icon's Introduction

Live Icon

GitHub GitHub code size in bytes GitHub top language GitHub language count GitHub tag (latest by date) GitHub issues

GitHub Repo stars GitHub forks

Compatibility

✅   Android
❌   iOS (active issue: iOS support)

Features

All the features listed below can be performed at the runtime.

✅   Change App Icons
✅   Change App Label

Quick Start

Step 1: Include plugin to your project

dependencies:
  live_icon: <latest version>

Step 2: Add activity-alias in AndroidManifest.xml

...
...
<application
    android:label="live_icon_example"
    android:icon="@mipmap/ic_launcher">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:windowSoftInputMode="adjustResize">
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme"
            />
        <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background"
            />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

    <!-- Live Icon Addition -->
    <activity-alias
        android:name=".DarkTheme"
        android:enabled="false"
        android:icon="@mipmap/dark_theme"
        android:label="DarkThemeLabel"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>

    <activity-alias
        android:name=".LightTheme"
        android:enabled="false"
        android:icon="@mipmap/light_theme"
        android:label="LightThemeLabel"
        android:targetActivity=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity-alias>
    <!-- Live Icon Addition -->

    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />

</application>
...
...

Step 3: Create classes

Create java/kotlin files with the same name as provided in activity-alias.

In the above AndroidManifest.xml example, 2 activity-alias are provided, so the number of java/kotlin files will be 2. Example:

1. DarkTheme.java

package com.hackthedeveloper.live_icon_example;

public class DarkTheme {
}

2. LightTheme.java

package com.hackthedeveloper.live_icon_example;

public class LightTheme {
}

One thing to note here is that, we have added two extra activity as activity-alias, and we now have 3 activity in total.

Step 4: Initialise plugin

List all the activity-alias class names. NOTE: MainActivity will also be added here as it containes the launch intent.

LiveIcon.initialize(
    classNames: ['MainActivity', 'DarkTheme', 'LightTheme'],
);

Step 5: Switch App icon

Use switchIconTo to switch app icons. It takes in the className that must match the desired activity-alias android:name.

await liveIcon.switchIconTo(
    className: 'DarkTheme',
);

Project Created & Maintained By

Subham Praharaj

GitHub followers

Divyanshu Shekhar

GitHub followers

Contributions

Contributions are welcomed!

If you feel that a hook is missing, feel free to open a pull-request.

For a custom-hook to be merged, you will need to do the following:

Describe the use-case.

  • Open an issue explaining why we need this hook, how to use it, ... This is important as a hook will not get merged if the hook doens't appeal to a large number of people.

  • If your hook is rejected, don't worry! A rejection doesn't mean that it won't be merged later in the future if more people shows an interest in it. In the mean-time, feel free to publish your hook as a package on https://pub.dev.

  • A hook will not be merged unles fully tested, to avoid breaking it inadvertendly in the future.

Copyright & License

Code and documentation Copyright (c) 2021 Devs On Flutter. Code released under the BSD 3-Clause License.

flutter_live_icon's People

Contributors

divshekhar avatar skpraharaj avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

flutter_live_icon's Issues

[Android] Switch other icon will enabled other icon.

Hi Divshekhar

Describe the bug
After implementing the example, when you click to switch DarkTheme’s Icon,
The Icon of MainActivity will disappear, but the Icon of LightTheme and DarkTheme will exist together.

To Reproduce
Steps to reproduce the behavior:

  1. Follow the implementation steps
  2. Switch DarkTheme's Icon
  3. See error

Screenshots
1.This MainActivity Icon.

2.Click the DarkTheme's Button.

3.Switch Back to MainActivity.

Three Icon is enabled.😂😂

Solution

Search for keywords in the project: "DONT_KILL_APP"
Find the MethodCallImplementation.Java file

Find this line.
pm.setComponentEnabledSetting(cn, componentState, PackageManager.DONT_KILL_APP);

Add this code above it.

else{
     componentState = PackageManager.COMPONENT_ENABLED_STATE_DISABLED;
}

It Work.

BR
Johnny

MainActivity can't be found

Description
The bug is an error that is triggered when trying to switch the App Icon. For some personal project reasons, we need to set the main activity name as "io.flutter.embedding.android.FlutterActivity" instead of ".MainActivity".

This makes the package code not recognize either the definitions of the "MainActivity" or "io.flutter.embedding.android.FlutterActivity" class names and throw an exception.

To Reproduce

  1. Upgrade a project using the reference: link
  2. Implement the flutter_live_icon package with an ExampleTheme using the described steps
  3. Initialize the theme
  4. Try to switch to the theme

Expected behavior
The icon switch should work properly.

Logs

Example of the error log when initializing and switching to the "MainActivity" class:

[ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, Component class com.mypackage.myproject.MainActivity does not exist in com.mypackage.myproject, null, java.lang.IllegalArgumentException: Component class com.mypackage.myproject.MainActivity does not exist in com.mypackage.myproject
E/flutter (21631): 	at android.os.Parcel.createExceptionOrNull(Parcel.java:2429)
E/flutter (21631): 	at android.os.Parcel.createException(Parcel.java:2409)
E/flutter (21631): 	at android.os.Parcel.readException(Parcel.java:2392)
E/flutter (21631): 	at android.os.Parcel.readException(Parcel.java:2334)
E/flutter (21631): 	at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:7173)
E/flutter (21631): 	at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:2793)
E/flutter (21631): 	at com.hackthedeveloper.live_icon.MethodCallImplementation.switchIconTo(MethodCallImplementation.java:79)
E/flutter (21631): 	at com.hackthedeveloper.live_icon.MethodCallImplementation.onMethodCall(MethodCallImplementation.java:51)
E/flutter (21631): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (21631): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter (21631): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/flutter (21631): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter (21631): 	at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (21631): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (21631): 	at android.os.Looper.loopOnce(Looper.java:201)
E/flutter (21631): 	at android.os.Looper.loop(Looper.java:288)
E/flutter (21631): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
E/flutter (21631): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (21631): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/flutter (21631): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/flutter (21631): Caused by: android.os.RemoteException: Remote stack trace:
E/flutter (21631): 	at com.android.server.pm.PackageManagerService.setEnabledSetting(PackageManagerService.java:24140)
E/flutter (21631): 	at com.android.server.pm.PackageManagerService.setComponentEnabledSetting(PackageManagerService.java:23984)
E/flutter (21631): 	at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:3291)
E/flutter (21631): 	at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:8840)
E/flutter (21631): 	at android.os.Binder.execTransactInternal(Binder.java:1179)
E/flutter (21631): 
E/flutter (21631): )
E/flutter (21631): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (21631): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (21631): <asynchronous suspension>
E/flutter (21631): #2      LiveIcon.switchIconTo (package:live_icon/live_icon.dart:18:5)
E/flutter (21631): <asynchronous suspension>
E/flutter (21631): 

Example of the error log when initializing and switching to the "MainActivity" class:

E/flutter (18259): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(error, Component class com.mypackage.myproject.io.flutter.embedding.android.FlutterActivity does not exist in com.mypackage.myproject, null, java.lang.IllegalArgumentException: Component class com.mypackage.myproject.io.flutter.embedding.android.FlutterActivity does not exist in com.mypackage.myproject
E/flutter (18259): 	at android.os.Parcel.createExceptionOrNull(Parcel.java:2429)
E/flutter (18259): 	at android.os.Parcel.createException(Parcel.java:2409)
E/flutter (18259): 	at android.os.Parcel.readException(Parcel.java:2392)
E/flutter (18259): 	at android.os.Parcel.readException(Parcel.java:2334)
E/flutter (18259): 	at android.content.pm.IPackageManager$Stub$Proxy.setComponentEnabledSetting(IPackageManager.java:7173)
E/flutter (18259): 	at android.app.ApplicationPackageManager.setComponentEnabledSetting(ApplicationPackageManager.java:2793)
E/flutter (18259): 	at com.hackthedeveloper.live_icon.MethodCallImplementation.switchIconTo(MethodCallImplementation.java:79)
E/flutter (18259): 	at com.hackthedeveloper.live_icon.MethodCallImplementation.onMethodCall(MethodCallImplementation.java:51)
E/flutter (18259): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262)
E/flutter (18259): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:296)
E/flutter (18259): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:320)
E/flutter (18259): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
E/flutter (18259): 	at android.os.Handler.handleCallback(Handler.java:938)
E/flutter (18259): 	at android.os.Handler.dispatchMessage(Handler.java:99)
E/flutter (18259): 	at android.os.Looper.loopOnce(Looper.java:201)
E/flutter (18259): 	at android.os.Looper.loop(Looper.java:288)
E/flutter (18259): 	at android.app.ActivityThread.main(ActivityThread.java:7839)
E/flutter (18259): 	at java.lang.reflect.Method.invoke(Native Method)
E/flutter (18259): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
E/flutter (18259): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
E/flutter (18259): Caused by: android.os.RemoteException: Remote stack trace:
E/flutter (18259): 	at com.android.server.pm.PackageManagerService.setEnabledSetting(PackageManagerService.java:24140)
E/flutter (18259): 	at com.android.server.pm.PackageManagerService.setComponentEnabledSetting(PackageManagerService.java:23984)
E/flutter (18259): 	at android.content.pm.IPackageManager$Stub.onTransact(IPackageManager.java:3291)
E/flutter (18259): 	at com.android.server.pm.PackageManagerService.onTransact(PackageManagerService.java:8840)
E/flutter (18259): 	at android.os.Binder.execTransactInternal(Binder.java:1179)
E/flutter (18259): 
E/flutter (18259): )
E/flutter (18259): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (18259): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:177:18)
E/flutter (18259): <asynchronous suspension>
E/flutter (18259): #2      LiveIcon.switchIconTo (package:live_icon/live_icon.dart:18:5)
E/flutter (18259): <asynchronous suspension>

Result of the Flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.10.2, on macOS 12.0.1 21A559 darwin-arm, locale en-BR)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] VS Code (version 1.64.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

Update pub.dev package

Describe the bug
Could you please update the pub.dev package? The current version there creates two launcher icons not one. The current version in your repo is working but not published. Thank you :)

Need iOS Support!

Description
The plugin only supports Android for now. Need iOS support!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.