Android 工程下的写法
import android.net.Uri; // 需要导入的包 public static void openUrl() { Uri uri = Uri.parse("http://www.cmread.com/u/index"); Intent it = new Intent(Intent.ACTION_VIEW,uri); this.startActivity(it); }
通过 JNI , 在 C++ 端可以调用 openUrl 方法
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #include "platform/android/jni/JniHelper.h" #endif #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) JniMethodInfo minfo; bool isHave = JniHelper::getStaticMethodInfo(minfo,"com/og/common/OGMainActivity","openUrl","()V"); if (isHave) { minfo.env->CallStaticVoidMethod(minfo.classID,minfo.methodID); } #endif
这里就不在赘述。
IOS 下代码
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.cmread.com/u/index"]];