COCOS2D-X3.3RC0 Send SMS via JNI call to Android Java layer URI code

Source: Internet
Author: User

1, JNI does not repeat. Look at the previous blog 2, directly on the code 1) Java layer, directly added to 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: Jni/hellocpp/test class of. h and. CPP codes such as the followingtest.h
#ifndef test_h_#define Test_h_extern "C" {//c++ the Java function interface. This method is used in the Menucallback function in Helloworldscene. void Showtipdialog (const char* title,const char* msg); void Share ();} #endif
Test.cpp Note that these two pieces of code are changed 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 platform inference to the header file, such as the following code:
#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.