C++调用Java(借助JNI技术实现每日登陆的实现)
来源:互联网 发布:三国志13武将数据修改 编辑:程序博客网 时间:2024/06/02 02:19
<1>C++部分(直接调用Java,实现每日登陆功能)
void DayAwardLayer::loginAward(){CCLog("loginAward");#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //判断当前是否为Android平台 JniMethodInfo minfo; jobject jobj; if (JniHelper::getStaticMethodInfo(minfo, "com/qingxue/game/GunStreet", "getInstance", "()Ljava/lang/Object;")) { jobj = minfo.env->CallStaticObjectMethod(minfo.classID, minfo.methodID); if (JniHelper::getMethodInfo(minfo, "com/qingxue/game/GunStreet", "interval", "()I")) { CCLog("jobj start");if(jobj == NULL) {return;}conLoginDays = minfo.env->CallIntMethod(jobj, minfo.methodID); if(conLoginDays>7) conLoginDays=7;CCLog("jobj end");} } #endif for(int i=0 ; i<conLoginDays-1 ; i++){CCObject* obj = itemArray->objectAtIndex(i);CCNode* item = (CCNode*)obj;item->setVisible(false);CCObject* obj2 = blinkArray->objectAtIndex(i);CCNode* bli = (CCNode*)obj2;bli->setVisible(false);}}
总结:当调用的java方法返回值是int时, 用CallIntMethod, 比如判断用户是否安装了微信.调用的返回值为空时, 用CallVoidMethod
<2>Java部分(计算是否是连续登陆,如果不是,还要重新重置第一次登陆时间)
public int interval() {SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");SharedPreferences mySharedPreferences= getSharedPreferences("date",Activity.MODE_PRIVATE); SharedPreferences.Editor editor = mySharedPreferences.edit(); //debug// editor.putBoolean("firstLogin", true);// editor.commit(); if(mySharedPreferences.getBoolean("firstLogin", true)){editor.putBoolean("firstLogin", false);String curDate = df.format(new Date()).toString();//curDate = "2014-01-09";Log.e("curDate", curDate);editor.putString("firstLoginDate", curDate);editor.putString("preLoginDate", curDate);editor.commit(); }String firstLoginDate = mySharedPreferences.getString("firstLoginDate", "2014-01-11"); String preLoginDate = mySharedPreferences.getString("preLoginDate", "2014-01-11"); String curLoginDate = df.format(new Date()).toString(); // curLoginDate = "2014-01-31";Log.e("Date:",firstLoginDate+" : "+ preLoginDate + " : "+ curLoginDate);long from=0;try {from = df.parse(firstLoginDate).getTime();} catch (ParseException e){e.printStackTrace();}long betweet = 0;try {betweet = df.parse(preLoginDate).getTime();} catch (ParseException e){e.printStackTrace();}long to=0;try {to = df.parse(curLoginDate).getTime();} catch (ParseException e){e.printStackTrace();}int bwto = (int) ((to - betweet) / TRUEDAY);if(bwto != 1){//editor.putBoolean("firstLogin", true);Log.e("firstLogin:", "间断了");editor.putString("firstLoginDate", curLoginDate);editor.putString("preLoginDate", curLoginDate);editor.commit(); return 1;} int result = (int) ((to - from) / TRUEDAY);Log.e("interval",result+""); editor.putString("preLoginDate", curLoginDate); editor.commit(); return result+1;}<3>提示对话框(如公司信息等)
public void aboutDialogShow(){ AlertDialog.Builder builder1 = new AlertDialog.Builder(GunStreet.this); builder1.setTitle("关于").setMessage("游戏类型:射击枪战\n" +"客服电话: 0371-63788390\n" +"游戏版本: 本游戏的版权由河南青学电子科\n" +"技有限公司所有,游戏中的文字图片等内容\n" +"均为游戏版权所有者的个人态度或立场,炫\n" +"彩公司对此不承担任何法律责任。").setCancelable(false).setPositiveButton("确定", new DialogInterface.OnClickListener() {public void onClick(DialogInterface dialog, int id) {dialog.cancel();}}).create().show();}
0 0
- C++调用Java(借助JNI技术实现每日登陆的实现)
- 【Java】Java调用C/C++程序的实现(jni)
- Chap5:使用JNI技术实现java程序调用第三方dll(c/c++)文件的功能
- 使用JNI技术实现java程序调用第三方dll(c/c++)文件的功能
- JNI技术实现JAVA程序调用dll
- JNI简单实现Java调用C++/C的HelloWorld
- JNI简单实现Java调用C++/C的HelloWorld
- JNI简单实现Java调用C++/C的HelloWorld
- JNI编程中C调用Java实现。
- jni实现C语言调用Java程序
- JNI 实现java 与 c ++ 调用
- JNI实现Java调用C/C++语言
- 用JNI实现java调用C
- Android JNI实现简单的c层调用Java层函数(C层调用Java层Toast进行提示)
- java调用C/C++生成的dll动态链接库----借助JNI
- JNI实现java调用C语言实现底层代码
- android studio 调用jni,实现Java调用C语言程序
- 借助postman实现模拟登陆
- 开源SVM库libSVM介绍
- 一个简单例子让你彻底理解java回调机制
- 2014/7/16
- 拨号及dialog列表
- 编程之美hiho一下第二周Trie树
- C++调用Java(借助JNI技术实现每日登陆的实现)
- DBus 入门与应用 -- DBus 的 C 编程接口
- hdu 4493 Tutor
- 提高代码编码的效率,习惯很重要!
- Fatal error: Call-time pass-by-reference has been removed in
- hdu 1753 高精度加法,带小数点
- poj 1151 Atlantis 纯矩形面积并
- 关于java中如何判断ResultSet是否为空的问题
- Next Permutation