Heim > Datenbank > MySQL-Tutorial > cocos2dx代码调用本地浏览器步骤详解

cocos2dx代码调用本地浏览器步骤详解

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-07 15:24:31
Original
1445 Leute haben es durchsucht

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) { JniMethod

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");

Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage