- Home /
Modifying Android intents via C# in Unity
I must admit, I am quite unfamiliar with the Android ecosystem, having spent the last few years working on iOS-only games. Currently doing my first android port, and I need to specify a path to the external OBB file for the publisher SDK we're using. The extent of my direction from them is this:
This path ususlly obtained in runtime by obb-downloader plugin. So all you need is add to the intent of main activity: getIntent().putExtra("KD_OBB_PATH", OBBPath);
I found this obb-downloader plugin for Unity on the asset store, but it's littered with comments about how it does not function in Unity 4.x. And well, that example I got is Java code, and from what I can tell, the "easy" way is to make my own Java plugin for Android specifically to make this single call? I've been trying to avoid that headache and trying to do it right in a Start() function before the rest of my SDK-handling code:
if (Application.platform == RuntimePlatform.Android)
{
AndroidJavaClass unityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unityPlayer.GetStatic<AndroidJavaObject> ("currentActivity");
AndroidJavaClass Environment = new AndroidJavaClass("android.os.Environment");
string obb_package = currentActivity.Call<string>("getPackageName");
const string obbPath = "Android/obb";
string OBBPATH = "";
using (AndroidJavaObject externalStorageDirectory = Environment.CallStatic<AndroidJavaObject>("getExternalStorageDirectory"))
{
string root = externalStorageDirectory.Call<string>("getPath");
OBBPATH = String.Format("{0}/{1}/{2}", root, obbPath, obb_package);
Debug.Log ("OBBPATH is: " + OBBPATH);
}
currentActivity.Call<AndroidJavaObject>("getIntent").Call("putExtra", "KD_OBB_PATH", OBBPATH);
}
This code is erroring out on the attempt to call "getIntent":
02-20 10:24:16.788: I/Unity(16245): AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='getIntent' signature='()Ljava/lang/Object;' in class Lcom/prime31/UnityPlayerNativeActivity;
I'm having a heck of a time trying to google any solutions to this, so I came here, to my last resort! Any suggestions?
Your answer
Follow this Question
Related Questions
Porting ios game to android 1 Answer
Porting Android Game(developed in Eclipse) to Unity3D 1 Answer
A node in a childnode? 1 Answer
Unity / QCAR Activity on Android 1 Answer
Sending data using intent from Unity app to Android app 0 Answers