Hello Guys, I was making Android Unity Plugin(Android Studio Library Project) to show a simple local Notification
on Button Click. But i am getting the above exception.
Thankyou
LOGCAT FROM ANDROID MONITOR
09-17 10:06:33.762 3253-3274/? I/Unity: UnityEngine.AndroidJavaException: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/NotificationCompat$Builder;
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/app/NotificationCompat$Builder;
at first.unityplugin.com.unitylibrary_1.Notification.ShowNotification(Notification.java:16)
at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
at com.unity3d.player.UnityPlayer.a(Unknown Source)
at com.unity3d.player.UnityPlayer$c$1.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:135)
at com.unity3d.player.UnityPlayer$c.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.app.NotificationCompat$Builder" on path: DexPathList[[zip file "/data/app/com.Origins.Plugin-1/base.apk"],nativeLibraryDirectories=[/data/app/com.Origins.Plugin-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassL).
JAVA CODE FOR SHOWING NOTIFICATION
package first.unityplugin.com.unitylibrary_1;
import android.content.Context;
public class Notification {
public static String ShowNotification(Context context)
{
try {
android.support.v4.app.NotificationCompat.Builder builder = new android.support.v4.app.NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.arrow_up_float)
.setContentText("Conntext Text")
.setContentTitle("Content Title");
android.app.NotificationManager notificationManager = (android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(001, builder.build());
return "Success";
}
catch(Exception e)
{
return String.valueOf(e);
}
}
}
C# Code For Calling Method to Show Notification
public Text text;
public void ShowNotification()
{
#if UNITY_ANDROID
try{
string status ="Class Not Found" ;
AndroidJavaClass NotificationClass = new AndroidJavaClass("first.unityplugin.com.unitylibrary_1.Notification");
if(NotificationClass != null)
{
status = NotificationClass.CallStatic<string>("ShowNotification",context);
text.text = status;
}
else{
text.text = status;
}
}
catch (Exception e)
{
string a = e.ToString();
text.text = a;
Debug.Log(a);
}
#endif
}