I’ve just started working with Plugins, and I just can’t get past this one issue. I can call functions that return strings just fine, I’ve been able to create a plugin to download files to the SD card (needed to use SSL), but I just can’t seem to create a plugin that provides a native view or intent in any way. This is my first foray into writing anything native for the droid, so hopefully I’m just missing something obvious.
I started with the Unity Plugin example using a prebuilt JNI Library that can be found here. I’m using the build file (and thus Apache ANT) to compile my java.
So, now I’ve got a C# file with the following code pertaining to this:
...
loadWebView = AndroidJNI.GetMethodID(cls_JavaClass, "loadWebView", "(Ljava/lang/String;)Ljava/lang/String;");
...
private string openWebView() {
JavaVM.AttachCurrentThread();
// get the Java String object from the JavaClass object
jvalue[] setTypeParameters = new jvalue[2];
setTypeParameters[0] = new jvalue();
setTypeParameters[0].l = AndroidJNI.NewStringUTF("http://www.army.mil");
//IntPtr str_fileInfo = JNI.CallObjectMethod(JavaClass, downloadFile, setTypeParameters);
IntPtr str_fileInfo = AndroidJNI.CallObjectMethod(JavaClass, loadWebView, setTypeParameters);
Debug.Log("str_fileInfo = " + str_fileInfo);
This calls the function - as I can remove all the java code and just have it return a string, and it works properly.
My java code, though, seems to just freeze up the application. The file it calls is as follows:
public class JavaClass {
private Activity mActivity;
public JavaClass(Activity currentActivity) {
Log.i("JavaClass", "Constructor called with currentActivity = " + currentActivity);
mActivity = currentActivity;
}
...
public String loadWebView(String fURL) {
webActivity showWeb = new webActivity();
showWeb.showWebView(fURL);
return "loaded";
}
This then calls into another file which contains this code:
...
public class webActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void showWebView(String fURL) {
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.webview1);
WebSettings webSettings = wv.getSettings();
webSettings.setBuiltInZoomControls(true);
wv.loadUrl(fURL);
}
}
At some point, this Java all compiled. But I’ve gone through so many alterations trying to get things to work, I’ve ended up with things no longer compiling due to two errors on the line “webActivity showWeb = new webActivity();” (can’t find either symbol webActivity in that line). Even when it did compile, though, when I hit the button I had linked to call the Java code, it just froze.
In the end, I’m not sure what I’m missing here. I’m not completely shocked it’s not working, but I just can’t figure out for what reason (or reasons) it isn’t working due to my unfamiliarity with the native android code. Any help would be very, very much appreciated, as I’ve attempted about 5-6 completely different routes to this point, and this is the closest I’ve come.