window.resolveLocalFilesystemUrl in ionic 2 - android

I need to save a downloaded file in my ionic 2 path and use that ineteral url path.
for downloading: using file-transfer plugin.
const fileTransfer = new Transfer();
fileTransfer.download(trackObj.remoteUrl,cordova.file.dataDirectory+"audio/"+filename).then((entry)=>{
console.log("download completed:"+entry.toURL());
});
entry.toURL() is giving path like file://...... in need to use that path to play using Media plugin. But, Media plugin is not accepting path with file://...,
this.playerStatic = new MediaPlugin(internalFilePath,onStatusPlayerUpdate);
so, on googling foundout: https://forum.ionicframework.com/t/ios-9-cant-play-audio-video-files-that-are-downloaded-to-device/37580/4
so using "cdvfile://localhost/library-nosync/" + fileSrc; as a temporary solution. Its not working for android.
so to be able to use in both platforms, i should be able to follow other solution, where the path will be resolved to InternalURL. when i try
window.resolveLocalFileSystemURL(src, function(dir){});
its saying resolveLocalFileSystemURL is not a function.
anybody can help me with it? how to use window.resolveLocalFileSystemURL in ionic 2?

I am using it in ionic 3, for iOS build. Please check the code:
this.file.resolveLocalFilesystemUrl(this.file.dataDirectory).then((entry) => {
console.log("Success! Got a DirectoryEntry",entry);
});
Here, I am using cordova-plugin-file but I think it should work for cordova-plugin-file-transfer also. Please try and let me know, if there is any issue.

Related

Ionic Cordova FileUpload error: Not allowed to load local resource

I am new to Ionic and I am trying to upload an image taken from camera that is stored in Android filesystem:
var ft = new FileTransfer();
console.log('Uploading: ' + fileURL);
ft.upload(fileURL,
encodeURI("http://192.168.192.62:3000/api/meals/picture"),
pictureUploaded,
function(error) {
console.err(error);
$ionicLoading.show({template: 'Ooops error uploading picture...'});
setTimeout(function(){$ionicLoading.hide();}, 3000);
},
options);
var pictureUploaded = function() {
console.log('uploaded!');
$ionicLoading.hide();
};
fileUrl is pointing to an existent image: file:///data/data/com.ionicframework.nutrilifemobile664547/files/Q2AtO1462636767466.jpg
In chrome://inspect/#devices console I get the following error and it looks like because of the error the FileOptions are also not properly sent, this is the error (Not allowed to load local resource):
Cordova version: 6.1.1
Ionic version: 1.7.14
This happens when you use the "livereload" option with Ionic.
Try running in normal mode
With ionic webview >3.x, you have to use convertFileSrc() method.
For example if you have a myURL local variable such as file:// or /storage.
let win: any = window; // hack ionic/angular compilator
var myURL = win.Ionic.WebView.convertFileSrc(myURL);
Another possible reason is that you have a webview plugin installed (like https://github.com/ionic-team/cordova-plugin-ionic-webview or just https://github.com/apache/cordova-plugin-wkwebview-engine). Also this will not allow to use cdvfile:// protocol as well.
It might be too late but... you could convert native path to blob using File then convert blob to URL using URL.createObjectURL(blob) and passing/setting as src to your html element. This is unnecessary for production environment but you could use it for development with -lc. It might work
07-Dec-2018
This is the version where it works for me on Ionic 3.9.2 app.
Remove the latest version of webview and then:
i.e. ionic cordova plugin add cordova-plugin-ionic-webview#1.2.1
https://github.com/ionic-team/cordova-plugin-ionic-webview/releases/tag/v1.2.1
Note: This version works fine with normalizeURL() method.

Phonegap 3.3 resolveLocalFileSystemURI Cannot get Android data/data folder

I used to be able to run this without problem to get to the databases folder of my Android App:
window.resolveLocalFileSystemURI('file:///data/data/{package name}/databases',
function (entry) {
alert(entry.fullPath);
}, rlfsOnErrors);
However, the statement returns error when I am using file-transfer plugin v0.4.2. When I switched back to file-transfer plugin v0.3.3, there is no problem. When I am using v0.4.2, I can only gain access to file:///data/media/xxxx directory and not file:///data/data/xxxx.
Anyone has any idea how I can workaround this ? Currently, I am sticking to v0.3.3, but I am sure there is some way to workaround this ?
Thanks.

Android: Phonegap 3.1.x fail to load geolocation plugin

We are using Phonegap 3.1.0-0.15.0 and the application chocked when trying to access location information.
Works fine in iOS however the App chock on Android
We are using:
navigator.geolocation.getCurrentPosition(app.location.onSuccess, app.location.onError);
and we also tried:
var geo = cordova.require('cordova/plugin/geolocation');
geo.getCurrentPosition(app.location.onSuccess, app.location.onError);
The logcat mentioned the following:
Could not find cordova.js script tag. Plugin loading may fail. at file:///android_asset/www/phonegap.js:1511
Uncaught module cordova/plugin/geolocation not found at file:///android_asset/www/phonegap.js:56
The plugin was added using:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
Are we doing something wrong ?
Thank you in advance
/Edwardo.
Just to answer my own questions. I removed all the plugins manually and then add them (including the problematic geolocation plugin) using the following command:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git
That solved my issue.
Edward.

phonegap file transfer with space in the file name

I'm using Cordova 1.9.0 for an Android App. The same code, on IOS works fine.
On Android, i find a problem for the file trasfert from remote location to local.
The problem is on the file name: someone has space. I try to do
.replace(" ","%20")
but doesn't work. It gives me the following error
07-03 12:06:32.503: E/FileTransfer(337): java.io.FileNotFoundException: http://www.mydomain.com/sa02 -.jpg
There was a bug in FileTransfer upload which a fix was checked in for 1.9.0.
https://issues.apache.org/jira/browse/CB-978
url = url.replace(/ /g,"%20");
PhoneGap 1.9.0 and 2.0.0 break fileTransfer.download() for names with spaces.
The workaround for now until PhoneGap 2.1.0 comes out is
var source = encodeURI(file path here);
source = source.replace(/%/g,"%25");

window.plugins undefined when trying to use the phonegap plugins on android

I can't load the plugins in android. I have added the plugin to the plugins.xml list, have added the java code in my project. But still when I call window.plugins I get undefined object. Why is this happening? BTW I'm trying to use the share plugin - https://github.com/phonegap/phonegap-plugins/tree/master/Android/Share
Just to be clear, I have added the phonegap.js file and the share.js file containing the JS plugin code. Also I have used the EmailComposer plugin for iphone with same code and it works on iphone, i.e. on iphone the window.plugins object it isn't undefined.
I fixed the exact same issue after noticing... i forgot to reference phonegap-1.1.0.js in my html. I also had to uncomment PhoneGap.addPlugin('share', new Share()); in share.js.
I had the same issue and I think I found the problem with phonegap.
You should go see on this thread, it may explain why you can't access your plugins : Phonegap background geolocation plugin not found
In phonegap 1.1.0 we can't call the windows.plugin what we need to in your share.js instead of
PhoneGap.addConstructor(function() {
});
add navigator.your plugins.js=new WebIntent(); (Java file) and call the plugin as navigator.your javascript plugin name in your javascript.

Categories

Resources