js端
if (cc.sys.os == cc.sys.OS_ANDROID) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "openUrl", "(Ljava/lang/String;)V", "http://down.lelegongshe.com/");
}
java端
import android.content.Intent;
import android.net.Uri;
static private AppActivity self = null;
public static void openUrl(String url)
{
Uri uri = Uri.parse(url);
Intent it = new Intent(Intent.ACTION_VIEW, uri);
self.startActivity(it);
}
IOS
+(void) openBrowser: (NSString * )urlStr{
NSString *url = [NSString stringWithFormat:@"%@", urlStr];
[[UIApplication sharedApplication] openURL :[NSURL URLWithString:url]];
}
本文介绍了在跨平台游戏开发中如何实现不同操作系统下(Android、iOS及JavaScript)打开网页的功能。通过具体的Java、Objective-C及JavaScript代码示例,展示了如何根据不同平台调用相应的系统API来打开指定的URL。
1231

被折叠的 条评论
为什么被折叠?



