Highlighted

CameraRoll saving on Android from Animate

Contributor ,
Nov 29, 2018

Copy link to clipboard

Copied

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!

TOPICS
Development

Views

674

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

CameraRoll saving on Android from Animate

Contributor ,
Nov 29, 2018

Copy link to clipboard

Copied

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!

TOPICS
Development

Views

675

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Nov 29, 2018 0
Contributor ,
Nov 29, 2018

Copy link to clipboard

Copied

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..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 29, 2018 0
Contributor ,
Nov 29, 2018

Copy link to clipboard

Copied

Oh!  This actually works on my phone!

It just throws an error on the Google Nexus tablet!

Hm.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 29, 2018 0
Adobe Community Professional ,
Nov 29, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 29, 2018 0
Contributor ,
Nov 29, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 29, 2018 0
Adobe Community Professional ,
Nov 29, 2018

Copy link to clipboard

Copied

Checking of the permissions will still be needed for pre-Android 6, so that the user is giving permission at the time they install the app.

I misread something before, it seems you are doing it the new way. Looking at my code, that is pretty much the same, and your code, this is one difference:

  if (CameraRoll.supportsAddBitmapData) {

  cameraRoll=new CameraRoll();

I don't see that second line in your code, or any private var cameraRoll:CameraRoll;

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 29, 2018 1
Contributor ,
Nov 30, 2018

Copy link to clipboard

Copied

Thx Colin.  That makes sense about permissions.  Got it.

Oh yes, good call!  I do have that line in my code though.. But I do seem to have deleted it here for some dumb reason.  Thank you so much for taking the time to catch that!  I have:

var cameraRoll:CameraRoll = new CameraRoll();

right near the beginning.  Sorry, I must have taken it out accidentally when trying to simply the code to post here >_<

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2018 0
Enthusiast ,
Nov 29, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 29, 2018 1
Contributor ,
Nov 30, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2018 0
Contributor ,
Nov 30, 2018

Copy link to clipboard

Copied

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...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2018 0
Contributor ,
Nov 30, 2018

Copy link to clipboard

Copied

I'm giving up on this and moving on, hoping it won't affect many people...

I got a few more testers who said it worked for them.  But they identified their device as "Android smartphone" which wasn't exactly helpful

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 30, 2018 0