opening URLs in external browser

Did you included JNI headers? Look at any cococs2d-x class that uses JNI for reference (example: cocos2dx/platform/android/CCImage.cpp).

I ended up putting it in the Jnihelper.cpp and changing the code to:

void openURLJNI(const char* url)
{
    JniMethodInfo t;
    if (getMethodInfo_(t
                    , "org/cocos2dx/lib/Cocos2dxActivity"
                    , "openURL"
                    , "(Ljava/lang/String;)V"))
    {
        jstring StringArg1 = t.env->NewStringUTF(url);
        t.env->CallStaticVoidMethod(t.classID, t.methodID, StringArg1);
    }
}

I realized afterwards that I can’t access the internet through to emulator, but it does appear to at least launch the browser with that address.

Merged into official version already?

I believe that they have said this is an unwanted feature in Cocos2D. Not sure why, I too love this!

2 Likes

hi…
ShellExecuteA(NULL, “open”, pszUrl, NULL, NULL, SW_SHOWNORMAL);
work on visul stadio but when i am port this on android it’s give error like:-
jni/…/…/Classes/GameMenu.cpp: In member function ‘void GameMenu::menuCloseCallback(cocos2d::CCObject*)’:
jni/…/…/Classes/GameMenu.cpp:54:59: error: ‘SW_SHOWNORMAL’ was not declared in this scope
jni/…/…/Classes/GameMenu.cpp:54:72: error: ‘ShellExecuteA’ was not declared in this scope
pls help me.

mohit parihar wrote:

ShellExecuteA(NULL, “open”, pszUrl, NULL, NULL, SW_SHOWNORMAL);
work on visul stadio but when i am port this on android it’s give error

ShellExecuteA will work only on Windows. For android you should do something similar to the code in previous posts posted by SEUNG-HYUN LEE

hey im making a game on Cocos2dx-2.1.0-wp8-2.0-alpha. I wanted to add a rate game button so i was thinking that i open the windows store link directly from my app using an external browser. Can you guide me how to do this on Cocos2dx-2.1.0-wp8-2.0-alpha. If there is a better way to add a rate game button id love to know that too

hey im making a game on Cocos2dx-2.1.0-wp8-2.0-alpha. I wanted to add a rate game button so i was thinking that i open the windows store link directly from my app using an external browser. Can you guide me how to do this on Cocos2dx-2.1.0-wp8-2.0-alpha. If there is a better way to add a rate game button id love to know that too

Hey,
you can open an URL on windows phone like this:

auto uri = ref new Windows::Foundation::Uri(“https://www.foo.bar”);
Windows::System::Launcher::LaunchUriAsync(uri);

2 Likes