SDKBox Share add image to email not working in Android

Hi there,

When I try to pass an image to an email in the Share Plugin, when it loads the mail in gmail I get a message saying “Permission denied for the attachment”. Any ideas how to fix this?

Runinng Cocosd2dx JS 3.13.1

Any help would be much apprecaited.

Can you provide some sample code for this issue, it will help us to identify what’s going on.

Hi there, thanks for the reply. Here is the code I am using to save an image (from a node capture) and then attach it to an email…

To save the image:

var renderer = new cc.RenderTexture(this._playAreaNode.getContentSize().width,
                this._playAreaNode.getContentSize().height, cc.Texture2D.PIXEL_FORMAT_RGBA8888);
        renderer.setAutoDraw(true);
        renderer.x = 0;
        renderer.y = 0;

        this._playAreaNode.x = (this._playAreaNode.getContentSize().width / 2);
        this._playAreaNode.y = (this._playAreaNode.getContentSize().height / 2);

        renderer.setSprite(this._playAreaNode);
        renderer.beginWithClear(255, 255, 255, 0, 0, 0);
        renderer.sprite.visit();
        renderer.end();


        var documentsDirectory = String(jsb.fileUtils.getWritablePath());
        var subDirectory = "Gallery/";

       var currentdate =  Date.now();

         var filename = currentdate + ".png";

  if (jsb.fileUtils.isDirectoryExist(documentsDirectory + subDirectory) == false) {
      
            jsb.fileUtils.createDirectory(documentsDirectory + subDirectory);
        }

        var saveDestination = subDirectory + filename;
        var saveSuccess = renderer.saveToFile(String(saveDestination), cc.IMAGE_FORMAT_PNG, true, saved);

To email the image:

        var index = this._masterImage.tag;
        
        var documentsDirectory = String(jsb.fileUtils.getWritablePath());
        var subDirectory = "Gallery/";
        var path = documentsDirectory + subDirectory + this._filenames[index];
        

        
           sdkbox.PluginShare.init();

var shareInfo = {};


        shareInfo.text = "Hi! \nThis is the sample email\n\n";
        shareInfo.title = "This is the sample email title.";



   shareInfo.image = path; 


shareInfo.link = "http://www.google.com";

All seems to be working fine in iOS FYI. Looking forward to hearing back from you.

Any update on this issue?

do you set permission in manifest,

if your image is saved in extern sd card, you should add this to android manifest

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

Hi there,

Yes, I have already added that. The issue is that the image is saved using “jsb.fileUtils.getWritablePath()”.

It seems this path cannot be accessed by other apps which results in the email client rejecting the link. I’ve created a workaround for now by copying the image first to “Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_PICTURES)” outside of the coocs2dx envrionment which seems to get it working. However, a non-hacky solution would be appreciated.

Thoughts?

jsb.fileUtils.getWritablePath() is /data/data/your.package.name/files/
email can’t access this directory.

copy to sdcard is the right way.