android cocos2dx游戏-添加截屏并分享微博功能

  又到了选择的时候,元宵节,公交遇贼,钱包里的身份证银行卡,统统被偷;被偷了,瞬间感觉“轻松了”,任何情况下我都可能回到原点,不是吗?不要担心选择必然所要做的放弃。

public class ShareSupport {
// when you want to use share(),firstly you should init acty.
public static Activity acty;


public static void share() {
new Thread(new Runnable(){

@Override
public void run() {
Intent intent = new Intent("android.intent.action.SEND");
intent.setType("image/*");
intent.putExtra(Intent.EXTRA_SUBJECT, "分享");
intent.putExtra(Intent.EXTRA_TEXT, "终于可以了!!!");
intent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:data/data/" + acty.getApplicationInfo().packageName+ "/share.png"));
Log.i("debug", "/data/data/" + acty.getApplicationInfo().packageName+ "/share.png");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
acty.startActivity(Intent.createChooser(intent, "分享"));
}

}).start();
}
}

拿出以前写android时的分享代码。

#include "jni_interfaces.h"
#include <android/jni/JniHelper.h>

extern "C" {
void Share()
{
cocos2d::JniMethodInfo jni_method_info;
cocos2d::JniHelper::getStaticMethodInfo(jni_method_info,"com/hortor/support/ShareSupport","share","()V");

if (jni_method_info.methodID)
{
jni_method_info.env->CallStaticVoidMethod(jni_method_info.classID, jni_method_info.methodID);
}
}
}

c++代码越写越简洁了,删掉很多冗杂的地方。

#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
Share();
CCLog("share ok");
#endif

在分享按钮初调用jni_interfaces中的Share()函数。

 ok不过有时,程序分享完会出现崩溃。

02-10 10:22:59.976: A/libc(2565): Fatal signal 11 (SIGSEGV) at 0x54e68000 (code=1)


看到群里有问, 如何从序列帧中获取一张图片,
我贴出游戏中截图代码:

    CCSize size = CCDirector::sharedDirector()->getWinSize();
CCRenderTexture* in_texture = CCRenderTexture::renderTextureWithWidthAndHeight((int)size.width, (int)size.height,kCCTexture2DPixelFormat_RGBA8888);
in_texture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) );
in_texture->setPosition( ccp(size.width/2, size.height/2) );
in_texture->setAnchorPoint( ccp(0.5f,0.5f) );

in_texture->begin();
this->visit();
in_texture->end();

CCLog("%d",in_texture->saveBuffer(kCCImageFormatPNG,"share.png",0,0,800,480));


 

write by fgd

转载于:https://www.cnblogs.com/wendao/archive/2012/02/09/adr_cpp_invoke_java_send.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值