CameraRoll saving on Android from Animate
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):
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!
