1、修改安卓端:CCApplication.cpph打开路径:cocos2dxplatformandroid目录,在类中增加函数:声明pub
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.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);
}
发布者:admin,转转请注明出处:http://www.yc00.com/web/1753987490a5104531.html
评论列表(0条)