zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    SystemVerilog搭建测试平台---第一章:验证导论
    二线制I2C CMOS串行EEPROM续
    二线制I2C CMOS串行EEPROM
    Codeforces 777E:Hanoi Factory(贪心)
    2019HPU-ICPC-Training-1
    Codeforces 777B:Game of Credit Cards(贪心)
    Codeforces 777D:Cloud of Hashtags(暴力,水题)
    Codeforces 777C:Alyona and Spreadsheet(预处理)
    Codeforces 888D: Almost Identity Permutations(错排公式,组合数)
    Codeforces 888E:Maximum Subsequence(枚举,二分)
  • 原文地址:https://www.cnblogs.com/wendao/p/adr_cpp_invoke_java_send.html
Copyright © 2011-2022 走看看