I know the paint module is very simple, and I have been using versions of it for years. Recently, (version 2.0.3), the pantView.toImage().media has stopped working. I actually us it to save a snapshot of the display so it is win.toImage().media. It gives me a 0 kb file. It detects a file, but it is empty. Any ideas how I can remedy the situation?
Appcelerator SDK 5.2.0 GA
Ti.Paint 2.0.3
Android OS target 6.0.x
Windows 8.1
var sigImg = win.toImage().media;
var filename = (Ti.App.currentWorkOrderId + "_signature.png");
var img = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename);
if(img.exists){
img.deleteFile();
}
img.write(sigImg);
Are you sure with Android 6 you have the storage permission enabled on the phone? Could it be it's not saving because it's not allowed? Remember with Android 6 you now must ask for permissions differently than previous Android versions...
Ray
I encountered the same problem. Here is my code for saving the images, it works very well. You can inspire you.. I hope you can solve your problem !
function path(imageName) {
return Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,imageName+".png");}
function loadImage(imageName) {
try {
var imageFile = path(imageName);
if(imageFile.nativePath) {
canvas.image = imageFile.nativePath;
console.log("LOAD !");
}
}
catch(err) {
console.log("ERREUR : ",err);
}}
function saveImage(imageName) {
try {
var imageFile = path(imageName);
imageFile.write(canvas.toImage());
console.log("SAVE !");
}
catch(err) {
console.log("ERREUR : ",err);
}}
Related
I am working on a personal project and I am using flutter to develop an app (cross platform) that reads in the user's health data from google fit (Android) or Apple Health. I am using this package and even the EXACT same code like in the documentation (I am currently only testing on Android):
Future fetchStepData() async {
int? steps;
// get steps for today (i.e., since midnight)
final now = DateTime.now();
final midnight = DateTime(now.year, now.month, now.day);
bool requested = await health.requestAuthorization([HealthDataType.STEPS]);
if (requested) {
try {
steps = await health.getTotalStepsInInterval(midnight, now);
} catch (error) {
print("Caught exception in getTotalStepsInInterval: $error");
}
print('Total number of steps: $steps');
setState(() {
_nofSteps = (steps == null) ? 0 : steps;
_state = (steps == null) ? AppState.NO_DATA : AppState.STEPS_READY;
});
} else {
print("Authorization not granted - error in authorization");
setState(() => _state = AppState.DATA_NOT_FETCHED);
}
}
Then I am calling this function with await and I also have inserted the correct permission in all Android Manifest files:
Also I set up an OAuth2 Client ID for the project and added my google account as a test user.
BUT THE FUNCTION SETS THE VARIABLE STEPS ALWAYS TO NULL? The boolean variable "requested" is true, so it seems like the actual connection is working?
I am really disappointed by myself guys and I really need help - THANK YOU!
I tried adding the correct android permissions, asking for permissions explicitly, different time intervalls but nothing worked for me, I always got a null value back.
I am trying to save images i take with the camera on my phonegap app to a more permanent destination. I run the app on iOS and Android so i need this to work on ios and android.
So far i can get the image file name and temporary storage path.
I can also get the base file system path for the device i am running (currently an Android Galaxy S7 edge).
However, i am unable to move/copy the file from the temporary storage to the new one as it fails.
Ive got the following code and ive got a try/catch around the code which moves the images. in the catch i have an alert which triggers always as there is something wrong with my code.
Ive tried changing the moveTo to CopyTo and changing the code from output.moveTo to things like cordova.file.moveTo without success.
If anyone could help i would be greatful.
Thanks Kind regards
const tempFilename = imageURI.substr(imageURI.lastIndexOf('/') + 1);
const tempBaseFilesystemPath = imageURI.substr(0, imageURI.lastIndexOf('/') + 1);
const newBaseFilesystemPath = cordova.file.dataDirectory;
var output=tempBaseFilesystemPath+tempFilename;
var saveOutput=newBaseFilesystemPath+tempFilename;
alert(tempFilename+","+tempBaseFilesystemPath+","+newBaseFilesystemPath+","+tempFilename);
try{
output.moveTo(tempBaseFilesystemPath, tempFilename, newBaseFilesystemPath,tempFilename)
.then(function (success) {
alert("done");
}, function (error) {
alert("not done");
});
}
catch{
alert("didnt run");
}
const storedPhoto = output;
localStorage.setItem('imageLoc',storedPhoto);
localStorage.setItem('goodPic','not');
},
function( message ) {
},
{
quality: 30,
destinationType: Camera.DestinationType.FILE_URI,
});
}
I am running into an issue where Android Studio is jumping over my breakpoint. I haven't run into this issue before and this recently started happening.
I am running Android Studio 2.3.1 on a MAC with no exotic plugins. Any ideas? Here is the code:
private fun getLatestZip(): File? {
var fileName = context.fileList().find { it.toUpperCase().contains("MBTA_GTFS") }
var dateTime = getGftsTimestamp()
var file: File?
if (dateTime == null) {
file = downloadLatestGfts() // skips the break on this line
if (file != null) {
printGftsTimestamp()
}
else {
Timber.e("Failed to download Gfts") // and goes straight to here
}
} else if (!fileName.isNullOrEmpty()) {....
EDIT ---
Here's a video to show you exactly what's happening. It could be a problem with kotlin. https://youtu.be/fJOIzD8ckv8
You need to place breakpoint in downloadLatestGfts() function or press F8 to go to next line (i.e file null check if statement).
Try to run the code putting a breakpoint on the line
if (dateTime == null)
and check whether the value of dateTime is null. It may be because of that null value the control goes straight to else condition.
I've been trying to run the following code but the callbacks [ok() and ko()] are not called.
Using Worklight 6.2 (Cordova 3.4).
function wlCommonInit() {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
success, fail);
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory
+ "www/index.html", ok, ko);
}
function ko(e) {
alert("NO");
}
function ok(fileEntry) {
alert("OK");
}
On the other hand requestFileSystem callbacks are called regularly.
The code snippet in the question will not work in Android due to a Cordova defect: https://issues.apache.org/jira/browse/CB-7273.
To progress further, it would help to understand what are your plans for the file itself.
Do you simply want the path to the file
Or do you want to alter the contents of the file?
Or?
You can read more about file system operations in Cordova in this question/answer: Where does LocalFileSystem.PERSISTENT point to?
I managed to access local fiiles in Worklight running an Android environment using a XMLHttpRequest:
//Works only on Android
function prendiCaricaRisorsaWorklight(percorsoPiuNomeFile) {
var xmlhttp = new XMLHttpRequest();
var risposta = "";
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4
&& (xmlhttp.status == 200 || xmlhttp.status == 0)) {
risposta = xmlhttp.responseText;
alert(risposta);
}
}
xmlhttp.open("GET", "file:///android_asset/www/default/"
+ percorsoPiuNomeFile, true);
xmlhttp.send(null);
}
Usage example:
prendiCaricaRisorsaWorklight("css/cssInterno.css");
prendiCaricaRisorsaWorklight("js/jsInterno.js");
This shows on Android an alert with the file content.
Device - Nexus One
OS - Android 2.3.4
Class - CameraRoll
Method - addBitmapData()
Error - [ErrorEvent type="error" bubbles=false
cancelable=false eventPhase=2 text="Error #2038: File I/O Error."
errorID=2038]
I'm trying to develop a photo app but am having problems saving the full sized version of the image back to the CameraRoll. This is very frustrating as I've only seen examples saving the stage to CameraRoll (which I can get to work).
Is there a limitation to saving back to CameraRoll?? When I try to load an image (2592 x 1944) and save it directly back to CameraRoll using addBitmapData(), I get the following error.
[ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error." errorID=2038]
Here's a code sample.
// class vars for CameraRoll and Loader
private var _cameraRoll:CameraRoll = new CameraRoll();
private var _loader:Loader = new Loader();
// launch _cameraRoll
private function launchCameraRoll(e:MouseEvent):void {
_cameraRoll.addEventListener(MediaEvent.SELECT, loadImg);
_cameraRoll.browseForImage();
}
// open selected image using _loader
private function loadImg(e:MediaEvent):void {
if (e.data.isAsync) {
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, saveImage);
_loader.loadFilePromise(e.data);
} else {
_loader.loadFilePromise(e.data);
saveImage();
}
}
// once loaded, save image immediately back to _cameraRoll
private function saveImage(e:Event = null):void {
_cameraRoll.addEventListener(ErrorEvent.ERROR, onError);
_cameraRoll.addEventListener(Event.COMPLETE, onComplete);
var bmd:BitmapData = new BitmapData(_loader.width, _loader.height);
bmd.draw(_loader);
_cameraRoll.addBitmapData(bmd);
}
// trace error
private function onError(e:ErrorEvent):void {
trace(e); // [ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Error #2038: File I/O Error." errorID=2038]
}
// show complete status
private function onComplete(e:Event):void {
trace("complete");
}
I had the same problem (even with real small images).
I solved it by uncommenting this line in the <android><manifestAdditions> section of the [Application]-app.xml file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
have you tried to save image in lower res? e.g. 1024x768? Maybe there is a limitation on the size that your device supports, I've found this or maybe the disk space is problem like mentioned here
best regards