Cocos2d-x3.3RC0通過JNI調用Android的Java層URI代碼傳送簡訊

來源:互聯網
上載者:User

標籤:cocos2d-x3.3rc0   簡訊   android   

1、Jni不在贅述,翻看前面部落格2、直接上代碼1)Java層,直接加在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 uri = Uri.parse("smsto:18928475901");Intent it = new Intent(Intent.ACTION_SENDTO,uri);it.putExtra("sms_body", "簡訊內容");System.out.println("test");it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//acty.startActivity(Intent.createChooser(intent, "分享"));acty.startActivity(it);}}).start();}}
2)Jni層:Jni/hellocpp/test類的.h和.cpp代碼如下test.h
#ifndef TEST_H_#define TEST_H_extern "C"{//C++調Java的函數介面,該方法在HelloWorldScene中menuCallback函數中使用。//void showTipDialog(const char* title,const char* msg);void Share();}#endif
test.cpp  注意,這兩段代碼是在之前代碼上修改的,部分代碼與此功能無關。請自行刪除。
#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 was not called");}}else{log("function share was not found");}}}
3)C++層
void HelloWorld::menuCloseCallback(Ref* pSender){#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)//    showTipDialog("exit","Exit,Really Go?");    Share();//調用tes.cpp中的Share()函數,該函數調用Java中的Share()函數#endif    #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)    exit(0);#endif}
4)注意在mk檔案加上test.cpp檔案路徑。在標頭檔處加上平台判斷,代碼如下:
#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)#include "../proj.android/jni/hellocpp/test.h"#endif


Cocos2d-x3.3RC0通過JNI調用Android的Java層URI代碼傳送簡訊

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.