又到了選擇的時候,元宵節,公交遇賊,錢包里的身份證銀行卡,統統被偷;被偷了,瞬間感覺“輕松了”,任何情況下我都可能回到原點,不是嗎?不要擔心選擇必然所要做的放棄。
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));
