1. Download our Official Android App: Forums for Android!

JNI Open Default Browser

Discussion in 'Android Development' started by Bonked, Aug 11, 2017.

  1. Bonked

    Bonked Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    17
    Joined:
    Aug 11, 2017

    Aug 11, 2017
    17
    3
    16
    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 (Text):
    1.  
    2. void func()
    3. {
    4.    android_app *app = RX->get_app();
    5.    
    6.    if (!app || !app->activity || !app->activity->vm )
    7.        return false;
    8.    
    9.    JNIEnv* jni = 0;
    10.    app->activity->vm->AttachCurrentThread(&jni, NULL);
    11.    if (!jni )
    12.        return false;
    13.    
    14.    
    15.    
    16.    
    17.    // get all the classes we want to access from the JVM
    18.    jclass classNativeActivity = jni->FindClass("android/app/NativeActivity");
    19.    jclass classWindowManager = jni->FindClass("android/view/WindowManager");
    20.    jclass classDisplay = jni->FindClass("android/view/Display");
    21.    jclass classDisplayMetrics = jni->FindClass("android/util/DisplayMetrics");
    22.    
    23.    if (!classNativeActivity || !classWindowManager || !classDisplay || !classDisplayMetrics)
    24.    {
    25.        app->activity->vm->DetachCurrentThread();
    26.        return false;
    27.    }
    28.    
    29.    
    30.    
    31.    
    32.    
    33.    
    34.    
    35.    jmethodID idNativeActivity_getWindowManager = jni->GetMethodID( classNativeActivity
    36.                                                , "getWindowManager"
    37.                                                , "()Landroid/view/WindowManager;");
    38.    
    39.    jobject windowManager = jni->CallObjectMethod(app->activity->clazz, idNativeActivity_getWindowManager);
    40.    if (!windowManager)
    41.    {
    42.        app->activity->vm->DetachCurrentThread();
    43.        return false;
    44.    }
    45.    
    46.    
    47.  
    48. // OPEN BROWSER
    49.    //app->activity->vm->AttachCurrentThread(&jni, 0);
    50.  
    51.    const char *url = "http://www.google.com";
    52.    jclass appClass = jni->GetObjectClass(windowManager);
    53.  
    54. //
    55.    jmethodID mid = jni->GetMethodID(appClass, "openURL", "(Ljava/lang/String;)V");
    56.    if(mid){
    57.        // found method name
    58.    }else{
    59.        // not found method name
    60.    }
    61.    
    62.    jni->CallVoidMethod(windowManager, mid, jni->NewStringUTF(url));
    63.    
    64.    app->activity->vm->DetachCurrentThread();
    65.  
    66. }
    67.  
    68.  
     

    Advertisement

Share This Page

Loading...