cocos2dx调用浏览器打开网址

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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信