How to Add Custom Toast Messages to Android APKs

In this detailed guide, we will walk you through the steps to add custom Toast messages to any Android APK file.

Whether you want a simple text message, a dialog with a button, a link, or even a colored message, we have got you covered.

Follow along to learn how to modify your APK files and enhance them with your custom messages.

Requirements

Note: Highly Recommend you to use MT Manager or APKToolkit since it will make everything easier, like decompiling, recompiling, signing the APK etc.

Step-by-Step Guide

Step 1: Decompile the APK

Use a decompiler tool like Apktool to decompile the APK file. You can download Apktool from its official website and follow the instructions to set it up.

apktool d yourfile.apk

Step 2: Modify AndroidManifest.xml

Open the AndroidManifest.xml file and look for the <action android:name="android.intent.action.MAIN"/> tag. Note the android:name attribute to identify the relevant activity class.

Note: If you are using APKToolkit to decompile the APK, then, it will show the main activity file when you drag the APK in it.

In this case, the main activity where you can add the toast is GameActivity.smali

<activity android:configChanges="locale|fontScale|keyboard|keyboardHidden|mcc|mnc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode" android:label="@string/app_name" android:launchMode="singleTop" android:name="net.circleous.domtweaks.StartActivity" android:screenOrientation="landscape">
  <intent-filter>
    <action android:name="android.intent.action.MAIN"/>
    <category android:name="android.intent.category.LAUNCHER"/>
  </intent-filter>
</activity>

Step 3: Locate and Edit the Smali File

Find the correct .smali file for the identified activity. For example, it might be located at smali/com/unity3d/player/UnityPlayerActivity.smali. Open this file and search for the onCreate method.

Step 4: Add Toast Message Code

Within the onCreate method, add the following code right after the .locals to create a simple Toast message:

.method protected onCreate(Landroid/os/Bundle;)V
.locals 1

 const/4 v0, 0x1
 const-string v1, "YOUR MESSAGE HERE"
 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

Replace "YOUR MESSAGE HERE" with your desired message.

Step 5: Recompile and Sign the APK

Recompile the modified APK file using Apktool or a similar tool.

apktool b your_decompiled_folder

Make sure you sign the APK file so that it can be installed on your device. You can use tools like APK Signer or jarsigner, or if you are using MT Manager then it will sign it for you.

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore yourfile.apk alias_name

Step 6: Install the Modified APK

Install the newly modified APK on an Android device to see the Toast message.

Advanced Toast Messages

1. Dialog Box with Button Toast

To create a dialog box with a button, you can use the following code:

.method protected onCreate(Landroid/os/Bundle;)V
.locals 1

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

 const-string v1, "YOUR MESSAGE HERE"
 invoke-virtual {v0, v1}, Landroid/app/AlertDialog$Builder;->setMessage(Ljava/lang/CharSequence;)Landroid/app/AlertDialog$Builder;

 const-string v1, "OK"
 new-instance v2, Landroid/content/DialogInterface$OnClickListener;
 invoke-direct {v2, p0}, Landroid/content/DialogInterface$OnClickListener;-><init>(Landroid/content/Context;)V
 invoke-virtual {v0, v1, v2}, Landroid/app/AlertDialog$Builder;->setPositiveButton(Ljava/lang/CharSequence;Landroid/content/DialogInterface$OnClickListener;)Landroid/app/AlertDialog$Builder;

 invoke-virtual {v0}, Landroid/app/AlertDialog$Builder;->show()V

2. Toast Message with Link

For a Toast message that includes a clickable link, use the following code:

.locals 2
# Create a new Toast message
 const/4 v0, 0x1
 const-string v1, "Your Message or Website Name"
 invoke-static {p0, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;
 move-result-object v0

 # Get the Toast view
 invoke-virtual {v0}, Landroid/widget/Toast;->getView()Landroid/view/View;
 move-result-object v1

 # Customize the Toast view to include a TextView with a clickable link
 new-instance v2, Landroid/widget/TextView;
 invoke-direct {v2, p0}, Landroid/widget/TextView;->(Landroid/content/Context;)V

 const-string v3, "Your Message or Wesbite Name"
 invoke-virtual {v2, v3}, Landroid/widget/TextView;->setText(Ljava/lang/CharSequence;)V

 # Make the TextView clickable and set a click listener
 const/4 v3, 0x1
 invoke-virtual {v2, v3}, Landroid/widget/TextView;->setClickable(Z)V

 # Create an Intent to open a URL
 new-instance v3, Landroid/content/Intent;
 const-string v4, "android.intent.action.VIEW"
 invoke-direct {v3, v4}, Landroid/content/Intent;->(Ljava/lang/String;)V

 const-string v4, "http://www.YOURWEBSITE.com"
 invoke-static {v4}, Landroid/net/Uri;->parse(Ljava/lang/String;)Landroid/net/Uri;
 move-result-object v4

 invoke-virtual {v3, v4}, Landroid/content/Intent;->setData(Landroid/net/Uri;)Landroid/content/Intent;

 # Set the OnClickListener to open the URL
 new-instance v4, Landroid/view/View$OnClickListener;
 invoke-direct {v4}, Landroid/view/View$OnClickListener;->()V

 invoke-virtual {v4, p0, v3}, Landroid/view/View$OnClickListener;->onClick(Landroid/view/View;Landroid/content/Intent;)V
 invoke-virtual {v2, v4}, Landroid/widget/TextView;->setOnClickListener(Landroid/view/View$OnClickListener;)V

 # Set the custom TextView as the Toast view
 invoke-virtual {v0, v2}, Landroid/widget/Toast;->setView(Landroid/view/View;)V

 # Show the Toast
 invoke-virtual {v0}, Landroid/widget/Toast;->show()V

3. Colored Toast Message

To create a colored Toast message, you can customize the Toast view:

.method protected onCreate(Landroid/os/Bundle;)V
.locals 1

 const/4 v0, 0x1
 const-string v1, "YOUR MESSAGE HERE"
 invoke-static {p0, v1, v0}, Landroid/widget/Toast;->makeText(Landroid/content/Context;Ljava/lang/CharSequence;I)Landroid/widget/Toast;
 move-result-object v0

 # Customize the Toast view
 invoke-virtual {v0}, Landroid/widget/Toast;->getView()Landroid/view/View;
 move-result-object v1

 # Change the background color
 const v2, 0xff00ff00  # ARGB color
 invoke-virtual {v1, v2}, Landroid/view/View;->setBackgroundColor(I)V

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

Conclusion

By following these steps, you can add various types of custom Toast messages to any Android APK file. Whether you want a simple message, a dialog box, a clickable link, or a colored message, you can enhance your APKs with these modifications.

Recompile and sign your APK, and enjoy your customized Android experience!

Leave a Comment