1, JNI does not repeat, look at the front blog 2, directly on the code 1) Java layer, directly add in the Appactivity.java
public class Appactivity extends cocos2dxactivity{public static Activity acty;protected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); acty = this;} static {system.loadlibrary ("Cocos2dcpp");} public static void Share () {New Thread (new Runnable () {@Overridepublic void Run () {//TODO auto-generated method Stuburi ur i = Uri.parse ("smsto:18928475901"); Intent it = new Intent (Intent.action_sendto,uri); It.putextra ("Sms_body", "SMS Content"); SYSTEM.OUT.PRINTLN ("test"); It.setflags (Intent.flag_activity_new_task);//acty.startactivity ( Intent.createchooser (Intent, "share")); acty.startactivity (it);}}). Start ();}}
2) Jni layer: the. h and. CPP codes for the Jni/hellocpp/test class are as followstest.h
#ifndef test_h_#define Test_h_extern "C" {//c++ the function interface of Java, which is used in Menucallback functions in Helloworldscene. void Showtipdialog (const char* title,const char* msg); void Share ();} #endif
Test.cpp Note that these two pieces of code are modified in the previous code, and some of the code is not related to this feature. Please delete it yourself.
#include "test.h" #include "cocos2d.h" #include "platform/android/jni/jnihelper.h" #include ". /.. /.. /classes/jnitest.h "#include <jni.h> #define CLASS_NAME" Org/cocos2dx/cpp/jnitesthelper "#define CLASS_NAMENEW" Org/cocos2dx/cpp/appactivity "using namespace Cocos2d;extern" C "{void Share () {bool Hasmethod; Jnimethodinfo T;hasmethod = Jnihelper::getstaticmethodinfo (t,class_namenew, "Share", "() V"), if (Hasmethod) {log (" Share function "), if (T.methodid) {T.env->callstaticvoidmethod (t.classid,t.methodid); log (" Function Share () was Called ");} Else{log ("function share is not called");}} Else{log ("function share is not found");}}}
3) C + + layer
void Helloworld::menuclosecallback (ref* psender) {#if (Cc_target_platform = = cc_platform_android)// Showtipdialog ("Exit", "exit,really Go?"); Share ();//Call the Share () function in Tes.cpp, which calls the Share () function in Java #endif #if (cc_target_platform = = Cc_platform_ios) Exit (0); #endif}
4) NoteAdd the Test.cpp file path to the Mk file. Add the platform judgment to the header file and the code is as follows:
#if (Cc_target_platform = = cc_platform_android) #include ". /proj.android/jni/hellocpp/test.h "#endif
COCOS2D-X3.3RC0 Send SMS via JNI call to Android Java layer URI code