• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

JNI Open Default Browser

Bonked

Newbie
I have the something like the following function and for the most part works, it can get the handles (and use for other examples), but here I'm trying to find "openURL" or similar...

1) Where is openURL, or use else?
2) Are there functions to get the list of methods available?

Thanks

* In this example for me it fails by not finding the method, just before the end... what method to use?

Code:
void func()
{
   android_app *app = RX->get_app();
   
   if (!app || !app->activity || !app->activity->vm )
       return false;
   
   JNIEnv* jni = 0;
   app->activity->vm->AttachCurrentThread(&jni, NULL);
   if (!jni )
       return false;
   
   
   
   
   // get all the classes we want to access from the JVM
   jclass classNativeActivity = jni->FindClass("android/app/NativeActivity");
   jclass classWindowManager = jni->FindClass("android/view/WindowManager");
   jclass classDisplay = jni->FindClass("android/view/Display");
   jclass classDisplayMetrics = jni->FindClass("android/util/DisplayMetrics");
   
   if (!classNativeActivity || !classWindowManager || !classDisplay || !classDisplayMetrics)
   {
       app->activity->vm->DetachCurrentThread();
       return false;
   }
   
   
   
   
   
   
   
   jmethodID idNativeActivity_getWindowManager = jni->GetMethodID( classNativeActivity
                                               , "getWindowManager"
                                               , "()Landroid/view/WindowManager;");
   
   jobject windowManager = jni->CallObjectMethod(app->activity->clazz, idNativeActivity_getWindowManager);
   if (!windowManager)
   {
       app->activity->vm->DetachCurrentThread();
       return false;
   }
   
   

// OPEN BROWSER
   //app->activity->vm->AttachCurrentThread(&jni, 0);
  
   const char *url = "http://www.google.com";
   jclass appClass = jni->GetObjectClass(windowManager);

// 
   jmethodID mid = jni->GetMethodID(appClass, "openURL", "(Ljava/lang/String;)V");
   if(mid){
       // found method name
   }else{
       // not found method name
   }
   
   jni->CallVoidMethod(windowManager, mid, jni->NewStringUTF(url));
   
   app->activity->vm->DetachCurrentThread();

}
 
Back
Top Bottom