So I\'m creating an Android app that uses Unity ... I am getting some assetbundle from Unity but I do not know the url before Unity starts. Thus Unity needs to call a funct
You could likely send the 'dynamic' url in your call to getURL. Do something like:
return plugin.Call<string>("getURL", new object[] {"http://thisIsMyUrl.com"});
and then your java looking like this:
public String getURL(Object newUrl) {
return newUrl.ToString();
}
I suggest ditch the NDK. Use the Android java plugin.
In YourPlugin.cs:
using UnityEngine;
using System.Collections;
using System.IO;
#if UNITY_ANDROID
public class UnityUrlPlugin {
// Logs the user out and invalidates the token
public static string getUrl() {
if( Application.platform != RuntimePlatform.Android )
return;
var pluginClass = new AndroidJavaClass("com.you.UnityUrlPlugin") ;
AndroidJavaObject plugin = pluginClass.CallStatic<AndroidJavaObject>("instance");
return plugin.Call<string>("getURL");
}
}
#endif
Then, in UnityUrlPlugin.java:
package com.you;
import android.content.ContentValues;
import android.content.Intent;
import android.os.Environment;
public class UnityUrlPlugin {
private static UnityUrlPlugin m_instance;
public static UnityUrlPlugin instance() {
if(m_instance == null)
m_instance = new UnityUrlPlugin();
return m_instance;
}
private UnityUrlPlugin(){
}
public String getURL() {
return "http://blah.com";
}
}
And throw UnityUrlPlugin.jar in to Assets/Plugins/Android
folder.
No need for NDK!