For my app, I'm using the Cordova CameraPreview plugin, to take pictures.
Once, a picture is taken, I get a path like this (and a 2nd one for the thumbnail, but not more):
/data/data/com.foo.bar/files/filename.jpg
Including the picture via
<img src="/data/data/...">
it works fine, so the path seems to be valid.
However, if I try to delete pictures, it doesn't work.
My Code:
window.resolveLocalFileSystemURL(the_path, function (result) {
alert("I'm in");
result.remove(function(){
alert("removed image");
});
});
The I'm in alert doesn't appear, in my console (Android Studio) I get the following error:
java.net.MalformedURLException: No installed handlers for this URL
Do I have to modify the URL, or what's wrong?
I found a solution via trial and error.
prepending
file://
to the path, so that it looks like
file:///data/data/com.foo.bar/files/filename.jpg
worked for me. But I've no idea, if this works in iOS, too.
Related
I'm using the official cordova camera plugin in order to load an image to an tag from a photo library, so I made a button to call the navigator.camera.GetPicture() method. After the click event on the bottom of the screen I get a "Get Picture" modal/toast with two options where can I browse my pictures: Gallery or Photos. If I choose the gallery everything works fine and I can repeat this multiple times. But If I choose the photos option I almost always get an error: "refused to load the image because it violates the following..." So any idea? I tried to modify the meta tags, but no result. Or how can I force the browsing only the gallery?
Thanks,
You can configure the options.
var cameraRollOptions = {
'sourceType': window.navigator.camera.PictureSourceType.PHOTOLIBRARY,
};
window.navigator.camera.getPicture(successHandler, errorHandler, cameraRollOptions);
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-camera/index.html#cameraoptions-errata-
Alright, here goes. I'm dealing with an ionic project. In this specific scenario we're dealing with testing the Android version of the app. I can get images from the file system just fine, they come back in the form of a string url that looks something like this,
content://com.android.providers.media.documents/document/image%3A5744
The processor that is then supposed to blob the file and pass it up the line looks like this:
return this.file.readAsArrayBuffer(urlData.url, urlData.fileName)
.then((item) => {
return new Blob([new Uint8Array(item)]);
})
.catch((err) => {
console.log(err.message)
}).then((res)=>{
return new Blob([res])
})
But then I get the error SECURITY_ERR, which the documentation doesn't really talk about.
This works just fine for the pictures I take with the camera, which all have urls that look like this
file:///storage/emulated/0/Android/data/<appname>/cache/1502211622334.jpg
The issue is, as far as i can find, there is no documentation on what causes this error. I have no idea what to change to make my code work. I have verified the URI is valid, using the checkFile method.
So it turns out you can't use content urls with file.readAsArrayBuffer instead you have to first resolve the url into something readAsArrayBuffer can understand. To do this, i used the ionic native filePath plugin.
Once it was installed and included in the page where I needed it, I used the
filePath.resolveNativePath(url)
method on my url, since this returns a promise, I chained my readAsArrayBuffer onto a then statement prepended to it. I did have to use an if statement to have branching paths for content urls (Which required resolveNativePath) and non-content urls which were already working.
This solution works as far as I can tell.
Im Trying show an image from web (external) with handlebar template
in my arq.handlebars I have this:
< img src="http://127.0.0.1:3000/system/products/avatars/034/thumb/image.jpg" data-rel="external"/ >
I also tried so:
< a class="imagem" style="background-image: url(http://127.0.0.1:3000/system/products/avatars/034/thumb/image.jpg);" data-rel="external" />
But it is not working. what appears is me: [?] (an icon like this)
Where did this path come from? Unless you're running something on your phone on Port 3000 this isn't going to work. The correct path in Cordova file:///android_asset/www/ assuming that you put your code in the assets/www directory of your project.
Either that or find out where the actual image is coming from and replace the path with the address of that server.
i have downloaded the phonegap example from its website.but it doesn't run.i can't find the reason.help me to get the solution please.when i run it shows
"The Web page at file:///andriod_asset/www/index.html could not be loaded as:
The requested file was not found.www/index.html"
I tried with three "///" instead of four, it worked for me. Give a try
super.loadUrl("file:///android_asset/www/index.html");
You've spelt android wrong here:
HERE!!!
file://>>>>>>andriod<<<<<<_asset/www/index.html could not be loaded as: The requested file was not found.www/index.html"
Try out:
file:///android_asset/www/index.html could not be loaded as: The requested file was not found.www/index.html"
Best of luck!
Just a quick comment for other's getting to this same problem, who doesn't have the spelling error. My new app using PhoneGap 0.9.4 was giving this same error box. The solution was to rename phonegap.0.9.4.js and phonegap.0.9.4.jar to just phonegap.jar and phonegap.js. After that it loads up.
You and I did the exact same thing -- flipped the i and the o in android.
Change "andriod" to "android" and it should work :)
I was using capitals for the folder WWW which was causing the same error to be thrown. I have now changed it to lowercase which works well now.
I have a WebView that I'm using to open some files stored in the assets/ directory of my project. It works fine for most of the files, but there's one in particular (and I'm sure others I haven't found) that it just will not open.
The file I'm having problems with is named:
"assets/ContentRoot/Photos/XXX Software Logo - jpg - 75%.JPG"
When I pass it to WebView, and it shows the error page, it shows it as:
"file:///android_asset/ContentRoot/Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%.JPG"
I then tried running URLEncoder.encode() on it and got the error page with the URL presented as:
"file:///android_asset/ContentRoot/Photos/XXX+Software+Logo+-+jpg+-+75%.JPG"
Neither of these URLs were able to open the file (and they both look okay to me). Anyone have any ideas?
UPDATE: If I encode the % by hand (using %25, as commonsware.com suggested) then it loads the image, but it tries to parse it as text, not as an image, so I just get a lot of (basically) garbage.
Also, referring to the image in an HTML document with a relative URL isn't working (probably because it's not being parsed as an image?):
<img src="../Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%.JPG" />
<img src="../Photos/XXX%20Software%20Logo%20-%20jpg%20-%2075%25.JPG" />
Okay, after spending way too long on this, I've figured out what's going on. Basically, if images stored in the assets/ directory contain a space (e.g., " ") in their file name, they won't render as images.
myWebView.loadUrl("file:///android_asset/testimage.jpg");
works fine. However,
myWebView.loadUrl("file:///android_asset/test+image.jpg");
just throws a not found error and
myWebView.loadUrl("file:///android_asset/test image.jpg");
// and
myWebView.loadUrl("file:///android_asset/test%20image.jpg");
show it improperly displayed (as text... see screenshot in question).
This unexpected behaviour is present on (at least) 1.5, 1.6, and 2.0 and I filed a bug report.
Try getting rid of the % in the filename. Or, escape it as %25.
I would guess that WebView only understands text related content types so it faithfully treating your JPG as base64 encoding, decodes and displays resulted gobble-goop as text. I don't really know if it's possible to set content type for WebView but as workaround you can try to throw img tag inside html tag and load resultet page. Also you probably can only use WebView#loadDataWithBaseUrl