加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在 Cocos2d-x 中打开一个链接

发布时间:2020-12-14 21:31:31 所属栏目:百科 来源:网络整理
导读:Android 工程下的写法 在 Java 端添加如下方法: 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)


Android 工程下的写法

在 Java 端添加如下方法:

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


JNI 的相关介绍可以参考:http://www.52php.cn/article/p-pkcqjrce-ze.html

这里就不在赘述。


IOS 下代码

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"http://www.cmread.com/u/index"]];

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读