Skip to main content
dolldivine
Inspiring
November 29, 2018
Question

CameraRoll saving on Android from Animate

  • November 29, 2018
  • 3 replies
  • 1303 views

Android has been a relative cake walk so far, except for image saving... What am I doing wrong?

I'm using Lars' code from an older post (edited):

camerRoll use in AIR 25, 26

I have WRITE_EXTERNAL_STORAGE checked off in the AIR for Android permission Settings.

Here is my code:

import flash.display.MovieClip;

import flash.display.Stage;

import flash.events.MouseEvent;

import flash.events.Event;

import flash.display.Bitmap;

import flash.display.BitmapData;

import flash.events.ErrorEvent;

import flash.media.CameraRoll;

import flash.events.PermissionEvent;

import flash.permissions.PermissionStatus;

var bitmapData:BitmapData = new BitmapData(stage.stageWidth,stage.stageHeight);

//function addListeners(): void {

if ((CameraRoll.supportsAddBitmapData == true)) {

saveToDisc.addEventListener(MouseEvent.CLICK, saveCamRoll);

saveToDisc.buttonMode = true;

feedback.text = "ABM supported";

} else {

saveToDisc.visible = false;

feedback.text = "ABM not supported";

}

//}

function saveCamRoll(event: MouseEvent): void{

cameraRoll.addEventListener(ErrorEvent.ERROR, onError);

cameraRoll.addEventListener(Event.COMPLETE, onSave);

//bitmapData.draw(MovieClip(root));

bitmapData.draw(stage);

if (CameraRoll.permissionStatus != PermissionStatus.GRANTED){

addendum.text = "permission not granted";

// cameraRoll is not yet granted...

cameraRoll.addEventListener(PermissionEvent.PERMISSION_STATUS, cameraRollPermissionStatus);

try {

cameraRoll.requestPermission();

addendum.text = "requested permission";

} catch (e: Error) {

// another request is in progress ...;

addendum.text = "error";

}

} else {

// All set. Calls addToCameraRoll now

addToCameraRoll();

addendum.text = "permission is granted";

}

//feedback.text = "savecamroll ran";

}

function addToCameraRoll(): void {

cameraRoll.addBitmapData(bitmapData);

checkMark.visible = true;

checkMark.play();

feedback.text = "addtocameraroll ran";

}

function cameraRollPermissionStatus(e: PermissionEvent): void {

cameraRoll.removeEventListener(PermissionEvent.PERMISSION_STATUS, cameraRollPermissionStatus);

if (e.status == PermissionStatus.GRANTED) {

addToCameraRoll();

addendum.text = "permission status checks out";

} else {

// permission denied

addendum.text = "permission denied";

}

}

function onError(e: ErrorEvent): void {

cameraRoll.removeEventListener(Event.COMPLETE, onSave);

cameraRoll.removeEventListener(ErrorEvent.ERROR, onError);

box3.text = "error";

}

function onSave(e: Event): void {

cameraRoll.removeEventListener(Event.COMPLETE, onSave);

cameraRoll.removeEventListener(ErrorEvent.ERROR, onError);

box4.text = "on complete";

}

So right now, these are the traces I get back:

feedback = "addtocameraroll ran"

addendum = "permission is granted"

box3 = "error"

box4 = blank

When I first checked off WRITE_EXTERNAL_STORAGE, the permissions pop up came up and I accepted and it hasn't asked since, which makes sense?

So I'm guessing the error is throwing everything off, but I don't know how to trace the error further?  I haven't been able to make the game test straight from Animate, so I don't know how to get more detail out of the debugging... (my Animate doesn't recognize either of my Android devices for some reason? Even though the computer recognizes that they're plugged in and file sharing is enabled)

As far as I can tell, no images are being saved.

So strange.. this is one thing that worked so easily on iOS!

This topic has been closed for replies.

3 replies

Lars Laborious
Legend
November 30, 2018

Try troubleshooting by tracing the specific error: box3.text = e.text;

dolldivine
Inspiring
November 30, 2018

Ah, I didn't know that trick!  Thanks Lars!

Error 2038

Hm, googling that just leads me back to this unsolved question haha:

cameraRoll.addBitmapData() causing #2038 file I/O error in AIR SDK 30

dolldivine
Inspiring
November 30, 2018

Yeah, I think this might be specific to my old tablet or something...

I tried a friend's app, who has a different saving code, and I couldn't get her cameraroll to work on this tablet either.

I'm starting to think it might be wise to just add a quick "hide menu" button so ppl can take their own screenshot if their phone is obsolete...

dolldivine
Inspiring
November 29, 2018

Oh!  This actually works on my phone!

It just throws an error on the Google Nexus tablet!

Hm.

Colin Holgate
Inspiring
November 29, 2018

It could be that AIR is now building for Android 6 and later. If that's the case you need to use the new way permissions work. AIR 24 was the first version to support that, and its release notes tell you how you need to ask for permissions. It works cross platform too, the same code works for iOS:

http://fpdownload.macromedia.com/pub/labs/flashruntimes/shared/air24_flashplayer24_releasenotes.pdf

An app you make that way will still work ok on Android 4 or 5.

dolldivine
Inspiring
November 29, 2018

Thx Colin!

I think I'm doing it the new way..?

Is the new way redundant with checking off the permission in the air for android settings?  Or are both still needed?

It's working on my phone, and I got a bunch of ppl to test it, and it worked for them too.  But then it turned out all three had the galaxy S7 so it was redundant testing haha.  So I'm wondering if the Nexus tablet is just defunct maybe.  Google gave it to me years ago and this is the first I've used it

Here's the file in case anyone else wanted to try...

https://www.dolldivine.com/post/glitter-cure.apk

dolldivine
Inspiring
November 29, 2018

Oh, I commented off the

function addListeners():

...because I didn't understand when it was being called.. as far as I can tell it never got called?  So I just took the contents out of the function..