1.找到ndk路径/sources/cocos2dx/platform/android/CCApplication.h添加方法
void openURL(const char* pszUrl);
2找到ndk路径/sources/cocos2dx/platform/android/CCApplication.cpp实现方法@H_301_7@
void CCApplication::openURL(const char* pszUrl)
{
@H_301_7@JniMethodInfo minfo;
@H_301_7@if (JniHelper::getStaticMethodInfo(minfo,
@H_301_7@"org/cocos2dx/lib/Cocos2dxActivity",//src路径下的文件
@H_301_7@"openURL", @H_301_7@ //Cocos2dxActivity文件的方法(下面会添加)
@H_301_7@"(Ljava/lang/String;)V")) //openURL()方法的参数类型Object,返回值类型void
@H_301_7@{
@H_301_7@jstring StringArg1 = minfo.env->NewStringUTF(pszUrl);
@H_301_7@minfo.env->CallStaticVoidMethod(minfo.classID,minfo.methodID,StringArg1);
@H_301_7@minfo.env->DeleteLocalRef(StringArg1);
@H_301_7@minfo.env->DeleteLocalRef(minfo.classID);
@H_301_7@}
}
@H_301_7@
3.找到Cocos2dxActivity.java导入命名空间@H_301_7@
import android.content.Intent;
import android.net.Uri;
@H_301_7@
4.Cocos2dxActivity.java中添加@H_301_7@
private static Activity wu= null;
@H_301_7@
protected void onCreate(final Bundle savedInstanceState) {
@H_301_7@super.onCreate(savedInstanceState);
@H_301_7@sContext = this;
@H_301_7@this.mHandler = new Cocos2dxHandler(this);
@H_301_7@wu = this;
@H_301_7@this.init();
@H_301_7@Cocos2dxHelper.init(this,this);
@H_301_7@}
@H_301_7@
//实现浏览器模块的调用
public static void openURL(String url)
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
wu.startActivity(i);
}
@H_301_7@
CCApplication::sharedApplication()->openURL("http://www.mcttqp.com/Download/djmxd.apk"); @H_301_7@