您的位置:首页 > 移动开发 > Cocos引擎

cocos2dx调用浏览器打开网址

2014-08-29 22:28 399 查看
1、修改安卓端:
CCApplication.cpp/h打开路径:cocos2dx/platform/android目录,在类中增加函数:
声明
public:

//jingz
void openURL(const char*pszUrl);

cpp实现:

//jingz
void CCApplication::openURL(const char* pszUrl)
{
JniMethodInfominfo;

if(JniHelper::getStaticMethodInfo(minfo,
"org/cocos2dx/lib/Cocos2dxActivity",
"openURL",
"(Ljava/lang/String;)V"))
{
jstring StringArg1 =minfo.env->NewStringUTF(pszUrl);
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,StringArg1);
minfo.env->DeleteLocalRef(StringArg1);
minfo.env->DeleteLocalRef(minfo.classID);
}
}

2、修改IOS端:
类似实现,IOS中.h/mm文件的OC代码中增加,在NS_CC_END前面增加
声明:

//jingz

voidopenURL(const char* pszUrl);

实现:

//jingz
void CCApplication::openURL(const char* pszUrl)
{
JniMethodInfominfo;

if(JniHelper::getStaticMethodInfo(minfo,
"org/cocos2dx/lib/Cocos2dxActivity",
"openURL",
"(Ljava/lang/String;)V"))
{
jstring StringArg1 =minfo.env->NewStringUTF(pszUrl);
minfo.env->CallStaticVoidMethod(minfo.classID, minfo.methodID,StringArg1);
minfo.env->DeleteLocalRef(StringArg1);
minfo.env->DeleteLocalRef(minfo.classID);
}
}

3、platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java增加网络模块的调用
引入包:import android.content.Intent;
import android.net.Uri;

声明类型:

//jingz

private static Activity me = null;

修改函数实现:

@Override

protected void onCreate(final Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

sContext = this;

this.mHandler = newCocos2dxHandler(this);

//jingz

me = this;

this.init();

Cocos2dxHelper.init(this, this);

}

//实现浏览器模块的调用

public static void openURL(Stringurl)

{

Intent i = newIntent(Intent.ACTION_VIEW);

i.setData(Uri.parse(url));

me.startActivity(i);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: