Intel XDK save pdf to sdcard filetransfer.download - android - javascript

Im buildning an application with intel xdk for android and ios. Im having trouble saving a pdf on the sdcard in android. im able to get the file directory of the unit and my alert text show that im progressing fine. But when i try to save the pdf nothing happens.
The application just skip the "fileTransfer.download(...)", no exception, no nothing.
Im probebly missing something but, is filetransfer not supported? been searching but no luck. All ideas are most welcome :o)
/Anders
my code:
function download()
{
window.appRootDirName = "download_test";
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
alert("device is ready");
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}
function fail() {
alert("failed to get filesystem");
}
function gotFS(fileSystem) {
alert("filesystem got");
window.fileSystem = fileSystem;
fileSystem.root.getDirectory(window.appRootDirName, {
create: true,
exclusive: false
}, dirReady, fail);
}
function dirReady(entry) {
window.appRootDir = entry;
alert("application dir is ready");
}
var filePathx = window.appRootDir.fullPath + "/test.pdf";
alert(filePathx);
try{
downloadFile = function() {
var fileTransfer = new FileTransfer();
var url = "http://myserver/file.pdf";
var filePath = window.appRootDir.fullPath + "/test.pdf";
fileTransfer.download(
url, filePath, function(entry) {
alert("download complete: " + entry.fullPath);
}, function(error) {
alert("download error" + error.source);
});
}
}
catch(e)
{
alert("error in filetransfer.download: " + e.message);
}
}

You need to include the WRITE_EXTERNAL_STORAGE permissions in the manifest file but the Intel XDK does not provide a UI to enable this permission. I will file a bug for you.
http://developer.android.com/reference/android/Manifest.permission.html#WRITE_EXTERNAL_STORAGE
You you should be able to use the Cordova for Android build. There is a PhoneGap Audio example application that I just tested but it does not work. I have filed an bug for the Intel XDK.
You can try a Cordova Android build by doing the following:
Use Intel XDK version 0876:
Click Start a New Project
Click Work with a Demo
Click PhoneGap Audio
Click USE THIS DEMO
Name your project
Click CREATE
Click the Develop tab
Click 'intelxdk.config.xml'
Copy this file for your own project
On line 4: change to the name of your project
On line 4: change to the name of your username without any symbols or spaces
You can check this by going to BUILD tab
Click on Cordova for Android BUILD button
Click UPLOAD CODE
See your Team name: displayed in the right hand 'Cordova Development Build' box above the green Build App Now button
Click Close Build Page
Click Develop and update your to match the Build screen
ie. Line 4: id="usernamewithoutsymbols.audioproject"
Note: I will also file a bug for a better UI needed to find the team name
Click BUILD tab
Click on Cordova for Android BUILD button
Click UPLOAD CODE
Click Build App Now
Click Download build
Install the .apk using adb install .apk
Launch the application
Tap the red record icon
Tap Stop
Tap Play
This app should create and save an audio file using Cordova APIs. I just tried this on a 4.0 and Android 2.3 phone and it did not work. Bug filed for you and I will update this post as the issue is tracked.
Documentation can be found at https://software.intel.com/en-us/html5/articles/using-the-cordova-for-android-ios-etc-build-option

Related

If link is 'http://google.com', it worked, but if i change link to my pdf url, it doesn't open

window.open("http://google.com") - works fine
window.open("data:application/pdf;base64,{base64EncodedString}") - opens fine on iOS device but not on Android.
Please use plugin file opener for that .Here is the plugin .
run this command in your working directory .
cordova plugin add cordova-plugin-file-opener2
basic usage
PDF File opener code
cordova.plugins.fileOpener2.open(
'/sdcard/Download/starwars.pdf', // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
'application/pdf',
{
error : function(e) {
console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
},
success : function () {
console.log('file opened successfully');
}
}
);
Please also check this url it is the plugin git directory and also have some example to open files.
A File Opener Plugin for Cordova
I would also suggest using In App Browser plugin.
You can install it by running:
cordova plugin add org.apache.cordova.inappbrowser
in your CLI (in case if you are using Cordova 3.x).
Earlier versions such (2.8.0, 2.9.0 etc) should have it pre-installed.
Ton open PDF documents in a new window use:
window.open('http://your-url.com/yourPDF.pdf', '_blank');
You might be able to use '_system option instead of '_blank' but i'm not sure about the outcome, it might open a system defined PDF viewer
Looks like I have to use
window.location.href = "data:application/pdf;base64,{base64EncodedString}"
instead of window.open("data:application/pdf;base64,{base64EncodedString}");

ngCordova capture not working on device

I'm am attempting to record audio using Ionic and ngCordova.
Here is my code:
$scope.captureAudio = function() {
var options = { limit: 3, duration: 10 };
$cordovaCapture.captureAudio(options).then(function(audioData) {
// Success! Audio data is here
alert(audioData);
console.log(audioData);
}, function(err) {
// An error occurred. Show a message to the user
alert(err);
});
};
When I run this in the emulator it works fine and brings up the voice recorder and when the recording is done it logs out the audioData.
When I upload it to ionic view and run it I get nothing. Not even an error.
Has anyone seen anything like this before ?
Thanks
Kevin
$cordovaCapture plugin is not yet supported by ionic view.
Please see the list of supported plugins in this link.
You can run the code in device directly using run command.
ionic run android

Cordova ibeacon; Send local notification after the app got killed, but does not work on android

I am using Cordova / Phonegap iBeacon plugin with ionicframework at my cordova project. I am tryin to send a local notification both on android and ios with cordova local notification plugin while entering monitored region , when the app is killed.
Here is my code :
document.addEventListener("deviceready", onDeviceReady, false);
function didDetermineStateForRegion(pluginResult) {
}
function didStartMonitoringForRegion (pluginResult) {
}
function didExitRegion(pluginResult) {
$cordovaLocalNotification.add({
id: 30244234234,
title: "Good By!",
text: "Hope to see you again."
}).then(function () {
});
}
function didEnterRegion (pluginResult) {
$cordovaLocalNotification.add({
title: "Welcome",
text: "Tap to launch app"
}).then(function () {
});
};
function didRangeBeaconsInRegion (pluginResult) {
}
function onDeviceReady() {
// Now safe to use device APIs
function createBeacon(uuid,nofiyState) {
var uuid = uuid; // mandatory
var identifier = 'estimote'; // mandatory
// throws an error if the parameters are not valid
var beaconRegion = new cordova.plugins.locationManager.BeaconRegion(identifier, uuid);
beaconRegion.notifyEntryStateOnDisplay = true;
return beaconRegion;
}
var delegate = new cordova.plugins.locationManager.Delegate();
delegate.didDetermineStateForRegion = didDetermineStateForRegion;
delegate.didStartMonitoringForRegion = didStartMonitoringForRegion;
delegate.didRangeBeaconsInRegion = didRangeBeaconsInRegion;
delegate.didEnterRegion = didEnterRegion;
delegate.didExitRegion = didExitRegion;
var beaconRegion = createBeacon('02681445-8D1B-4F58-99D4-B25F4B129A58',true);
// var beaconRegionBlue = createBeacon('02681445-8D1B-4F58-99D4-B25F4B129A58',1,,true);
cordova.plugins.locationManager.setDelegate(delegate);
// required in iOS 8+
//cordova.plugins.locationManager.requestWhenInUseAuthorization();
cordova.plugins.locationManager.requestAlwaysAuthorization();
cordova.plugins.locationManager.startMonitoringForRegion(beaconRegion)
.fail(console.error)
.done();
}
cordova plugins :
com.unarin.cordova.beacon 3.3.0 "Proximity Beacon Plugin"
de.appplant.cordova.plugin.local-notification 0.8.1 "LocalNotification"
nl.x-services.plugins.socialsharing 4.3.16 "SocialSharing"
org.apache.cordova.console 0.2.13 "Console"
org.apache.cordova.device 0.3.0 "Device"
cordova version : 4.3.0
this works fine for ios even if the app is killed but on android notifications cames only if app in the background. When i kill the app from task manager on android i never seen any local notification.
Is it possible to receive notification on android even if app is killed ?
thanks for help.
lets clear some stuff , there are states that yo are confusing :
App as a service
App running in background (i.e minimized).
App killed (not running at all)
in all cases the 3rd state when you kill app ( via long press back button in custom roms , or force stop from app menu in your OS ) , the app is simply removed from memory , no code is being excuted !
what usually is done in this case is automatically relaunching the service after it has been stopped check this answer , and as you can read :
it is really very bad pattern to run service forcefully against the
user's willingness.
there are so many cordova plugins to create BroadcasteReceiver , however the simple answer to your question , if app is killed it is not possible to receive notification .
But you should consider this: if user kills your app , it means it was done intentionally , so you shouldnt really worry if your app will work or not , as this is the user's issue , and not yours as a developer.

Intel XDK Barcode Scanner not working with Cordova Building

I created an application with Intel XDK that needs to scan the bar codes. So i used the intel.xdk.device.scanBarcode() method to realize this function. My problem is that the build of my application doesn't work if i build it with Cordova builder. This is my code:
function BarcodeScanner() {
try {
intel.xdk.device.scanBarcode();
}
catch (err) {
alert(err.message);
}
}
document.addEventListener("intel.xdk.device.barcode.scan", function (evt) {
intel.xdk.notification.beep(1);
if (evt.success == true) {
artsel = SearchArticoloByBarcode(evt.codedata);
DisplayInfoArt();
ConfArtCheck();
setTimeout(function () { $.ui.scrollToTop("page4", "200") }, 200);
}
else {
alert("Errore lettura");
}
}, false);
The build is successful, but when I run my app I catch an error that says: "Cannot read property 'scanBarcode' of undefined".
If I build the application with legacy builder the app works, but I'd like to use the other builder because the app created is faster and lighter.
The app works also with the Debugger. For now I'm working with an Android Phone (Nexus 5), but the app should run also on iOS and Windows Phone.
Does someone know something about this issue?
Thanks for the help.

is it possible to save contacts on windows phone 8 emulator permanently in phonegap

Hi i'm unable to save the contacts in my windows phone 8 emulator permanently.contacts are saving just for a temporary period in people app.when i open that emulator and save contacts in it. They are getting saved but when i close that emulator and again reopened..no any contacts are showing in that people app .I want to import that contacts in my app for sending some info.but i cant proceed as its not showing any contacts in it.I gone through phonegap tutorial tried this code also.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
var contact = navigator.contacts.create();
contact.displayName = "xyz";
var name = new ContactName();
name.givenName = "abc";
contact.name = name;
contact.save(onSaveSuccess,onSaveError);
function onSaveSuccess(contact) {
alert("Save Success");
}
function onSaveError(contactError) {
alert("Error = " + contactError.code);
}
AFAIK you can't do that because WP8 API doesn't allow that. You only have Read-only access to Contact API.
See the documentation.
EDIT: After reading a little more about your issues I found this one. So I think that your problem is with emulator only, that doesn't persist data after turned off.

Categories