📖 Tutorial How to add Custom Toast Messages, Dialogs & Splash Screens in MOD APK Files

Sbenny.com is trusted by 1,313,113 happy users since 2014.
Register

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User
Hello guys,

if you're wondering how to add a custom toast (see spoiler):



or custom splash screen (see spoiler):



for your hacked game, you came to the right place!

In this very simple tutorial I will show you how to do it!



TOAST MESSAGES - 90% OF UNITY 3D GAMES

Toast messages are not the simplest ones, especially if you're not used to decompile apk files and browse the smali folder, but I'll make it very simple and try to explain you in simple words.
We will modify a particular file inside the smali folder which is loaded at the moment we launch a game and we will tell this file to show a toast message.

First of all we need to see if it's a Unity3D-based game or not. How? Simple. If the .apk game has got the following path:

Code:
/Assets/bin/Data/Managed/
then YES, this game is a UNITY 3D-based game.

Steps are:

1) Grab the apk (of course)

2) Decompile the apk file (I personally use apktool, but there are many alternatives on the net, so find the most suitable for you).
If using APKTOOL:
a) Move the .apk file inside the root of the apktool (same path where the apktool.jar file is);
b) Right click+shift and select "Open Command Prompt here";
c) Type:
Code:
apktool d "name of the game.apk"
Quotes are needed almost always, I'll make it short so I suggest you guys to ALWAYS put quotes ( " " ) before and after the name of the apk file. Replace "name of the game" with the name of the apk file.
A new folder will be generated in the same directory of the .apk file and it will be called "name of the game". Open it.

3) Find the right path
Go to: "/name of the game/smali/com/unity3d/player/"

4) Dealing with the right file
Open the file "UnityPlayerActivity.smali" (I suggest Notepad++, a very good tool to read countless file extensions)

5) Search the right line
Press Ctrl+F (Search) and look for .method protected onCreate(Landroid/os/Bundle😉V
Only a result should come.
Now watch the following two lines. It should look like:

the .locals 2 can be .locals 3 or .locals 4 etc, no matter the number.
If you don't see the .prologue, just add it before the .locals like in the above screenshot, or ignore it, it's not a requirement.
Now the cool part, adding the Toast!

6) Add the Toast
Copy the following:
Code:
const/4 v0, 0x1

    const-string v1, "Hacked by YOUR_USERNAME_HERE \r\n Find us at forum.sbenny.com"

    invoke-static {p0, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v0

    invoke-virtual {v0}, Landroid/widget/Toast;->show()V
This code will load and display the Toast message every time you launch the app. Of course, replace "YOUR_USERNAME_HERE" with your real username.
Now, paste it right after the .locals and another blank line.

Final code should look like the following:



TIP : Repeating the above code will increase the lenght of your Toast Message. I don't personally suggest using the code more than 2 times since it's quite annoying to see a toast message for over 10 seconds.

7) Saving Changes
Once done, save the file and recompile the apk file by typing (in the command prompt):

Code:
apktool b "name of the folder"
8) Sign the apk using your favourite tool (I use this one, called one_click_signer)

9) Launch the game
If you correctly followed the above steps, launch the game and you should finally see:




TOAST MESSAGES - 10% OF UNITY GAMES AND EVERY NON-UNITY GAME
The process is similar:

1) Grab the apk (of course)


2) Decompile the apk file (I personally use apktool, but there are many alternatives on the net, so find the most suitable for you).
If using APKTOOL:
a) Move the .apk file inside the root of the apktool (same path where the apktool.jar file is);
b) Right click+shift and select "Open Command Prompt here";
c) Type:
Code:
apktool d "name of the game.apk"
Quotes are needed almost always, I'll make it short so I suggest you guys to ALWAYS put quotes ( " " ) before and after the name of the apk file. Replace "name of the game" with the name of the apk file.
A new folder will be generated in the same directory of the .apk file and it will be called "name of the game". Open it.


3) Find the right path
• Open the file "AndroidManifest.xml" you'll find in the decompiled apk folder, and search for: "android:name="android.intent.action.MAIN"
• Scroll up a few lines until you find, in the previous "<activity>" group the last occurrence of "android:name=" . Inside the quotation marks, you will find a code like the following:

Screenshot_14.jpg


In this example it's "com.my.ifly.StartActivity" but it changes with every game.

• Convert the code into a readable path
This is easier than it sounds. If we follow the example above, we'll have to replace all the points with the slash symbol and append ".smali" at the end of it, so:

com.my.ifly.StartActivity

becomes

com/my/ifly/StartActivity.smali

This is the path we should search for in order to find the right file to put our toast message in, so we move into:

smali/com/ifly/StartActivity.smali in order to find the right file

Notes: sometimes, you might need to open the "smali_classesX" (where X is a number) if you can't find the full path in the "smali" folder (and if smali_classesX folders exist), so it'd be, for example: smali_classes2/com/ifly/StartActivity.smali



4) Dealing with the right file
Now that we found the right file to work with, let's open it! In our example, it's "StartActivity.smali" (I suggest to open it using Notepad++, a very good tool to read and work with countless file extensions).

5) Search the right line
Press Ctrl+F (Search) and look for .method protected onCreate(Landroid/os/Bundle😉V (if you can't find the exact line, search for "onCreate", making sure you'll find a line which starts with ".method" and which has only "onCreate" as name, and not InvokeOnCreate or similar different names).

Only a result should come.

Now watch the following two lines. It should look like:

the .locals 2 can be .locals 3 or .locals 4 etc, no matter the number.
If you don't see the .prologue, just add it before the .locals like in the above screenshot.
Now the cool part, adding the Toast!

6) Add the Toast
Copy the following:
Code:
const/4 v0, 0x1

    const-string v1, "Hacked by YOUR_USERNAME_HERE \r\n Find us at forum.sbenny.com"

    invoke-static {p0, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v0

    invoke-virtual {v0}, Landroid/widget/Toast;->show()V
This code will load and display the Toast message every time you launch the app. Of course, replace "YOUR_USERNAME_HERE" with your real username.
Now, paste it right after the .locals and another blank line.

Final code should look like the following:



TIP : Repeating the above code will increase the lenght of your Toast Message. I don't personally suggest using the code more than 2 times since it's quite annoying to see a toast message for over 10 seconds.

7) Saving Changes
Once done, save the file and recompile the apk file by typing (in the command prompt):

Code:
apktool b "name of the folder"
8) Sign the apk using your favourite tool (I use this one, called one_click_signer)

9) Launch the game
If you correctly followed the above steps, launch the game and you should finally see the toast message added!


PRO TIPS:

• A Toast isn't the only thing you can add in that location. A good alternative is called "Dialog", which is composed by a Title, a Message and one (or more) buttons inside a system window. In order to add it, you just have to past this other code (instead of the toast), replacing the " ### PUT YOUR USERNAME HERE ### " with your username, of course.

Code:
new-instance v0, Landroid/app/AlertDialog$Builder;

    invoke-direct {v0, p0}, Landroid/app/AlertDialog$Builder;-><init>(Landroid/content/Context;)V

    const-string v1, "\uD83D\uDD14 Make sure this app is safe \uD83D\uDD14"

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setTitle(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    const-string v1, "This mod apk file is provided by ### PUT YOUR USERNAME HERE ###, only for Sbenny.com users! If you downloaded it from other sources, please uninstall it immediately because it will damage your device as other sites inject malicious code, and visit sbenny.com to download the genuine mod apk file!"

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    const-string v1, "I downloaded it at Sbenny.com \u263a"

    const/4 v2, 0x0

    invoke-virtual {v0, v1, v2}, Landroid/app/AlertDialog$Builder;->setPositiveButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setCancelable(Z)Landroid/app/AlertDialog$Builder;

    move-result-object v0

    invoke-virtual {v0}, Landroid/app/AlertDialog$Builder;->show()Landroid/app/AlertDialog;
• There's always a similar distance between the " android:name="android.intent.action.MAIN " line and the toast/dialog path in the AndroidManifest.xml file. Once you get used to it, you'll no longer need to use the Search to find them 🙂
• OnCreate could sometimes call other functions, you'll find out by reading what the OnCreate function actually does, if it invokes another "onCreate" inside it, and the toast/dialog isn't showing, it would be a good idea to look into the other file invoked 😉






CUSTOM SPLASH SCREENS - UNITY 3D GAMES

Splash Screens are called this way because of the file named "Splash.png" we will modify.

These kind of images can be only found inside Unity3D-based games (again) but this time it's an easier process.

Again, we need to ensure the game is a Unity3D-based game or not. So look for the following path:

Code:
/Assets/bin/Data/Managed/
otherwise, it means this is not a Unity 3D game.

Steps are:

1) Grab the apk (of course)

2) Rename the file extension from .apk to .zip (or Right click on the .apk file and select "Open With..." and choose "WinRar" and if not installed, search on Google or use this link for the x64 version or this link to download WinRar x32, if you're on Windows).

3) Find the right path

Go to: "/Assets/bin/Data/" if not present, you're not dealing with a Unity3D game.

4) Dealing with the right file
Take the file "Splash.png" out from the .zip file and move it to an easy-to-find path (I'm used to put all my hacks into the same folder).
TIP: It's usually one of the latest files in the "Data" folder, so you can directly scroll down till the end and you should find it.
TIP 2: on newer Unity Games, you might not found Splash.png in that location. If this is the case, you have 50% chance to find it in the following path: res/drawable/unity_static_splash.png. If you find it, just replace the unity_static_splash.png with your image (make sure it's called unity_static_splash.png). If you can't find it, I'm sorry but it means the game doesn't use Unity splashes and you shouldn't be able to add a splash screen for this game (you can still add a toast/dialog).

4.5) Backup (optional)
I suggest you guys making a copy of the original png image since sometimes this method doesn't work and could make the app crash (altough it's a very very rare occurrence).

5) Modify the image
I personally use Photoshop and never had any problems. I've heard about people having problems using Paint, so I suggest you guys to use Photoshop to make changes.
Edit the pic as your wish, add text, images or what you want. I don't personally suggest to change the image width/height.

6) Save the pic
With Photoshop go to File -> Save for Web and choose if PNG-8 (low quality but lower file size. Useful if you want to decrease the .apk file size) or PNG-24 (higher quality, better transparency but high file size. If you only mind about quality, go for it) and save it.

7) Moving it back
Once done, move it back to "Assets/bin/Data/" (or "res/drawable" if you're dealing with unity_static_splash.png) replacing the old one.

8) Renaming the file back to .apk
If you changed the extension to .zip, it's time to change it back to .apk😜

9) Sign the apk (optional) and Launch the game

The .apk file will be now UNSIGNED. This means you'd need root privileges and Lucky Patcher installed in order to install the app, otherwise you can simply sign it using your favourite tool (I use "One Click Signer"). Now, launch the game and, if everything goes fine, you should see a result like this:




For any feedbacks and questions, don't hesitate to reply below. Hope it helps 🙂
 
Last edited:

Axiom

G̴̠͂l̶̙̋ȉ̷̲t̷̰͂c̶̮͊ȟ̶̪ê̵͙d̷̰̿ ̴͉̈Ơ̵̟u̵̮̕t̵̼̊
From the Hell
SB Mod Squad ⭐
VIP
Member for 8 years
Re: Tutorial How to add Custom Toast Messages & Splash Scree

Very cool tutorial. Thank you
(y)
 

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User
Re: Tutorial How to add Custom Toast Messages & Splash Scree

Thank you so much Axiom :) 2nd part added!
 

NEMESIS

Novice Lv1️⃣
Member for 8 years
Re: Tutorial How to add Custom Toast Messages & Splash Scree

Sbenny said:
Thank you so much Axiom :) 2nd part added!
thanx Sbenny.. its clear as always :D
 

NEMESIS

Novice Lv1️⃣
Member for 8 years
How to make color with toast message? And if it possible if I put toast in playernativeactivity.smali (unity3d folder)?
 

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User
NEMESIS said:
How to make color with toast message? And if it possible if I put toast in playernativeactivity.smali (unity3d folder)?

Colors can be added with simple html tags such as:

Code:
    const-string v0, "<b>Hacked by <font color=#008000>Sbenny</font></b><br/>Find me at: <font color=#008000><u>sbenny.com/forums/</u></font>"

    invoke-static {v0}, Landroid/text/Html;->fromHtml(Ljava/lang/String;)Landroid/text/Spanned;

    move-result-object v0

    const/4 v1, 0x1

    invoke-static {p0, v0, v1}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v2

    invoke-virtual {v2}, Landroid/widget/Toast;->show()V
 

NEMESIS

Novice Lv1️⃣
Member for 8 years
Sbenny said:
NEMESIS said:
How to make color with toast message? And if it possible if I put toast in playernativeactivity.smali (unity3d folder)?

Colors can be added with simple html tags such as:

Code:
    const-string v0, "<b>Hacked by <font color=#008000>Sbenny</font></b><br/>Find me at: <font color=#008000><u>sbenny.com/forums/</u></font>"

    invoke-static {v0}, Landroid/text/Html;->fromHtml(Ljava/lang/String;)Landroid/text/Spanned;

    move-result-object v0

    const/4 v1, 0x1

    invoke-static {p0, v0, v1}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v2

    invoke-virtual {v2}, Landroid/widget/Toast;->show()V
Code:
.class public Lcom/unity3d/player/UnityPlayerNativeActivity;
.super Lcom/unity3d/player/UnityPlayerActivity;


# direct methods
.method public constructor <init>()V
    .locals 0

    invoke-direct {p0}, Lcom/unity3d/player/UnityPlayerActivity;-><init>()V

    return-void
.end method

# virtual methods
.method protected onCreate(Landroid/os/Bundle;)V
    .locals 2

    const-string v0, "<b>Hacked by <font color=#008000>Sbenny</font></b><br/>Find me at: <font color=#008000><u>sbenny.com/forums/</u></font>"

    invoke-static {v0}, Landroid/text/Html;->fromHtml(Ljava/lang/String;)Landroid/text/Spanned;

    move-result-object v0

    const/4 v1, 0x1

    invoke-static {p0, v0, v1}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v2

    invoke-virtual {v2}, Landroid/widget/Toast;->show()V

    const-string v0, "Unity"

    const-string v1, "UnityPlayerNativeActivity has been deprecated, please update your AndroidManifest to use UnityPlayerActivity instead"

    invoke-static {v0, v1}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

    invoke-super {p0, p1}, Lcom/unity3d/player/UnityPlayerActivity;->onCreate(Landroid/os/Bundle;)V

    return-void
.end method
i can't make it with these code. :?:
 

( ( dub ) )

APK Fanatic Lv5️⃣
VIP
Member for 7 years
Do toast messages not work at all on some games? I got it to work on all that I've tried but 1 game. Game is called Blyss.
 

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User

( ( dub ) )

APK Fanatic Lv5️⃣
VIP
Member for 7 years
[url=http://sbenny.com/forums/viewtopic.php?p=35529#p35529:dodpe1gm]Sbenny » 23 minutes ago[/url] said:
Do toast messages not work at all on some games? I got it to work on all that I've tried but 1 game. Game is called Blyss.
Is it a Unity Game?
Yeah, it is. I could not get one to work. Tried inserting the code in both "native" locations and had no success.
 

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User
Did you try placing the code here then? UnityPlayerActivity.smali (without Native)
 

( ( dub ) )

APK Fanatic Lv5️⃣
VIP
Member for 7 years
[url=http://sbenny.com/forums/viewtopic.php?p=35534#p35534:1c6rie59]Sbenny » 3 minutes ago[/url] said:
Did you try placing the code here then? UnityPlayerActivity.smali (without Native)
Yeah, that's what I meant. Sorry... Not both native, but tried both PlayerActivity sections.
 

BRILLIANT

Veteran Lv7️⃣
✔ Approved Releaser
Member for 6 years
Very cool and simple tutorial pretty nice , was wondering can I place a toast and a splash screen and it will work fine? Ty btw :walkingdroid:
 

johnhern

Modding Since 2017
Member for 6 years
Thanks for this, I was able to get the splash screen, but the smali mod kept crashing the app.
 

NdnszPstlr

Lurker Lv0️⃣
Member for 6 years
Re: Tutorial How to add Custom Toast Messages & Splash Scree

Toast Message does not load all apk.
Can I add Activity.smali into these files into MainActivity.Smali?
UnityPlayerNativeActivity.smali is not included in every apk file.
How to add toast message for every apk?
 

s810car

In Love Lv4️⃣
Member for 7 years
Re: Tutorial How to add Custom Toast Messages & Splash Scree

Toast Message does not load all apk.
Can I add Activity.smali into these files into MainActivity.Smali?
UnityPlayerNativeActivity.smali is not included in every apk file.
How to add toast message for every apk?
easy way: use my app you can find in this forum, ModIDE (search for it) it has an auto inject toast ability built in you just save your toast using the tool->add/edit toast menu. just do new project follow the setup wizard (leave toast checked), save toast in menu i mentioned, and build apk, its done!

a little harder way: use the method my program uses :D to me, aapt (in android studio) is much easier to use :
Code:
/path/to/aapt d badging ./path/to/apk
look for the line "launchable-activity, that will ALWAYS be the file you'll edit (the .smali of it after you apktool, only (kinda) downside of aapt is it doesn't do the decompiling, still need apktool) search for the protected method onCreate that the tutorial explains and follow from there
 

mribraqdbra

Novice Lv1️⃣
Member for 5 years
Hello, this my first post & I hope to help me!

your tutorial working 100% but how I can show the toast message only once apk installed only

thanks you for the great tutorial.
 

Nardo7

APK Fanatic Lv5️⃣
Member for 5 years
Colors can be added with simple html tags such as:

Code:
    const-string v0, "<b>Hacked by <font color=#008000>Sbenny</font></b><br/>Find me at: <font color=#008000><u>sbenny.com/forums/</u></font>"

    invoke-static {v0}, Landroid/text/Html;->fromHtml(Ljava/lang/String;)Landroid/text/Spanned;

    move-result-object v0

    const/4 v1, 0x1

    invoke-static {p0, v0, v1}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;

    move-result-object v2

    invoke-virtual {v2}, Landroid/widget/Toast;->show()V
The games crashed when i use Html to set colors.
I try adding some piece of codes and the problem is the "invoke-static {v0}, Landroid/text/Html;->fromHtml(Ljava/lang/String;)Landroid/text/Spanned;"

The one without colors works perfectly.
How can i resolve the one with html tags?
 

s810car

In Love Lv4️⃣
Member for 7 years
The games crashed when i use Html to set colors.
I try adding some piece of codes and the problem is the "invoke-static {v0}, Landroid/text/Html;->fromHtml(Ljava/lang/String;)Landroid/text/Spanned;"

The one without colors works perfectly.
How can i resolve the one with html tags?
Responding because you also went to try out ModIDE (my project), which has a tool to auto inject a toast with html tags accepted. My best guess is you didnt put the toast in the correct smali (some apks have multiple onCreate methods, if the main activity is a subclass). Look for a line near the top saying ".super", if it has that check the directory and file it mentions, see if that has an onCreate method as well. Toasts work sometimes when placed in the subclass while html tagged toasts usually only work if placed in the topmost onCreate method.

Alternatively, when testing out my project, you can use the add/edit toast feature to store a toast that when you build an apk project in it, will inject the toast in the correct file, and permits html.
 
Top