Quantcast
Channel: cocos2d-x - Cocos Forums
Viewing all articles
Browse latest Browse all 2748

Cocos2d-x Share on Android 6.0 Marshmallow issue

$
0
0

@energyy wrote:

Hello,

Can someone share his code snipet, to make screesnhot and share it thru Android intent on Android 6.0. The issue is that on android 6.0 we should request permissions read/write external storage in the code not in manifest file and I'm not sure how to do that in Cocos2d-x .

we using following Android code to share text/image for android <5

public static void showShareImageWithText(final String text,final String imagePath) throws IOException{

        /* Notes:
         You cannot pass the image just from the direction cocos saved - it's private;
         You need to save image to a public place, so that FB and other apps can reach it without any restricitons;
         Remove the image cocosa saved;
         Choose the share option;
         Set the tag for response;
         When image uploaded, check the response id and remove the image you've uploaded. (onActivityResult)
         */

            Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
            String localAbsoluteFilePath = saveImageLocally(bitmap);

            if (text.length() > 0 && imagePath.length() == 0) {
                Intent shareIntent = new Intent(Intent.ACTION_SEND);

                shareIntent.setType("text/plain");
                shareIntent.putExtra(Intent.EXTRA_TEXT, text);    //FB no longer allows you to prefill the sharing message. // will not work...
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                _appActivity.startActivityForResult(shareIntent, 332000);    //startActivity(shareIntent);

                return;
            }

            new File(Uri.parse(imagePath).toString()).delete();  // remove the one cocos saved

            if (localAbsoluteFilePath != null && localAbsoluteFilePath != "") {

                Intent shareIntent = new Intent(Intent.ACTION_SEND);
                Uri phototUri = Uri.parse(localAbsoluteFilePath);
                shareFile = new File(phototUri.getPath());

                if (shareFile.exists() == false) {
                    return;
                }

                shareIntent.setType("image/*");
                shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(shareFile));
                shareIntent.putExtra(Intent.EXTRA_TEXT, text);    //FB no longer allows you to prefill the sharing message. // will not work...
                shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                _appActivity.startActivityForResult(shareIntent, 333000);    //startActivity(shareIntent);
            } else {
                onShareDidFinish();
            }


    }

Posts: 2

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 2748

Latest Images

Trending Articles



Latest Images