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