Android Example App Icon Change at Runtime

Since it has been asked on some occasions about how to change the icon, I decided to find out.
https://www.b4x.com/android/forum/threads/how-to-change-app-icon-at-runtime.157576/
https://www.b4x.com/android/forum/threads/change-icon-at-runtime.104009/

Of course @Erel gives his opinion on the matter here:
https://www.b4x.com/android/forum/threads/change-icon-at-runtime.104009/post-652119

In this thread @chjk has left his progress on this and I decided to use his example based on activity and convert it to B4XPages which I attach below. All credits to Him.
  1. Don't forget to check the manifest.​

  2. Java code online in Main​

  3. The icon2.png file (read-only) in the folder ..\objects\res\drawable​

(Translated by Google)

1700863648360.jpeg
1700863717305.jpeg
'
 

Attachments

  • ChangeIcon.zip
    22.2 KB · Views: 290
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Since it has been asked on some occasions about how to change the icon, I decided to find out.
https://www.b4x.com/android/forum/threads/how-to-change-app-icon-at-runtime.157576/
https://www.b4x.com/android/forum/threads/change-icon-at-runtime.104009/

Of course @Erel gives his opinion on the matter here:
https://www.b4x.com/android/forum/threads/change-icon-at-runtime.104009/post-652119

In this thread @chjk has left his progress on this and I decided to use his example based on activity and convert it to B4XPages which I attach below. All credits to Him.
  1. Don't forget to check the manifest.​

  2. Java code online in Main​

  3. The icon2.png file (read-only) in the folder ..\objects\res\drawable​

(Translated by Google)

View attachment 148039 View attachment 148041'
After I have tried to change project in B4A (Not is B4XPages) It request runtime error. How do I do?
 

Theera

Well-Known Member
Licensed User
Longtime User

Theera

Well-Known Member
Licensed User
Longtime User

Attachments

  • ChangeIconApp.zip
    54.4 KB · Views: 137

mcqueccu

Well-Known Member
Licensed User
Longtime User
Hi mcqueccu
Please test my code. I don't find my problem what it is.
1. You did not add the ChangeIcon method

B4X:
Error occurred on line: 50 (Main)
java.lang.RuntimeException: Method: changeIcon not found in: b4a.example.main
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
    at b4a.example.main._usingicon2_click(main.java:459)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7540)
    at android.view.View.performClickInternal(View.java:7513)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29583)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:204)
    at android.os.Looper.loop(Looper.java:291)
    at android.app.ActivityThread.main(ActivityThread.java:8129)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:601)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1136)


FIX: ADD THIS TO THE MAIN MODULE

B4X:
#If JAVA
import android.content.ComponentName;
import android.content.pm.PackageManager;

public void changeIcon(String name){
    PackageManager pm = getPackageManager();
    pm.setComponentEnabledSetting( getComponentName(),PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(new ComponentName(this, name), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    //restart(pm);
}
#End if
 

Theera

Well-Known Member
Licensed User
Longtime User
1. You did not add the ChangeIcon method

B4X:
Error occurred on line: 50 (Main)
java.lang.RuntimeException: Method: changeIcon not found in: b4a.example.main
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
    at b4a.example.main._usingicon2_click(main.java:459)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7540)
    at android.view.View.performClickInternal(View.java:7513)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29583)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:204)
    at android.os.Looper.loop(Looper.java:291)
    at android.app.ActivityThread.main(ActivityThread.java:8129)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:601)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1136)


FIX: ADD THIS TO THE MAIN MODULE

B4X:
#If JAVA
import android.content.ComponentName;
import android.content.pm.PackageManager;

public void changeIcon(String name){
    PackageManager pm = getPackageManager();
    pm.setComponentEnabledSetting( getComponentName(),PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(new ComponentName(this, name), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    //restart(pm);
}
#End if
I think I don't be noticed. Because it is grey color. It should be blue color or others.
 

Theera

Well-Known Member
Licensed User
Longtime User
1. You did not add the ChangeIcon method

B4X:
Error occurred on line: 50 (Main)
java.lang.RuntimeException: Method: changeIcon not found in: b4a.example.main
    at anywheresoftware.b4j.object.JavaObject$MethodCache.getMethod(JavaObject.java:363)
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:120)
    at b4a.example.main._usingicon2_click(main.java:459)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:205)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:7540)
    at android.view.View.performClickInternal(View.java:7513)
    at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0)
    at android.view.View$PerformClick.run(View.java:29583)
    at android.os.Handler.handleCallback(Handler.java:942)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loopOnce(Looper.java:204)
    at android.os.Looper.loop(Looper.java:291)
    at android.app.ActivityThread.main(ActivityThread.java:8129)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:601)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1136)


FIX: ADD THIS TO THE MAIN MODULE

B4X:
#If JAVA
import android.content.ComponentName;
import android.content.pm.PackageManager;

public void changeIcon(String name){
    PackageManager pm = getPackageManager();
    pm.setComponentEnabledSetting( getComponentName(),PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
    pm.setComponentEnabledSetting(new ComponentName(this, name), PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
    //restart(pm);
}
#End if

Is there way to add this module not in main,but in bas file of module,and then compile to be library for B4A?
 

mcqueccu

Well-Known Member
Licensed User
Longtime User

Mariano Ismael Castro

Active Member
Licensed User
@Mariano Ismael Castro can you implement this for Adaptive Icons

I would like to help with this but I can't use B4i, I don't have an Apple developer account to create the certificate for my iPhone. Additionally, I don't have much experience with Objective C but maybe I can get it right away.
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
I would like to help with this but I can't use B4i, I don't have an Apple developer account to create the certificate for my iPhone. Additionally, I don't have much experience with Objective C but maybe I can get it right away.
I mean for Android Adaptive Icons. Most apps do not use single Icon but basically 3 types or more consisting of transparent, foreground and background image. Check this post on adaptive icons. So am asking if this library can use the adaptive icon instead


 

Theera

Well-Known Member
Licensed User
Longtime User
In my openion,
Why Erel don't create #IconApp in #project attribute of B4A,B4J,B4i?
 
Top