Android phonegap show image from external with handlebar - android

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.

Related

android emulator - What is the format of virtualscene\posters=#Variant

I m trying to change the images of photo from command line, to automate a integrated tests of an apk. But I dont know what format the image becames when put manualy from the android emulator ide.
When I add a Image manually from here
Like this code
In file .android/avd//AVD.conf
Have this line virtualscene\posters=#Variant and after a code of the image like
\0\0\0\b\0\0\0\x1\0\0\0\b\0w\0\x61\0l\0l\0\0\0\n\0\0\0\x90\0\x43\0:\0/\0P\0r\0o\0g\0r\0\x61\0m\0 \0\x46\0i\0l\0\x65\0s\0/\0\x41\0n\0\x64\0r\0o\0i\0\x64\0/\0\x41\0n\0\x64\0r\0o\0i\0\x64\0 \0S\0t\0u\0\x64\0i\0o\0\x31\0/\0j\0r\0\x65\0/\0j\0r\0\x65\0/\0\x62\0i\0n\0/\0\x63\0o\0\x64\0i\0g\0o\0 \0\x64\0\x65\0 \0\x62\0\x61\0r\0r\0\x61\0.\0p\0n\0g
like the imgage
I dont know what is this code, of image

How to delete an image with phonegap/cordova

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.

Phonegap/Cordova: img tag not displaying images from SDcard

I'm new to Phonegap/Cordova and building an app using MaterializeCSS and JQuery on Android OS 5.1. I have a problem that no images in the IMG tag seem to be loading, but the file paths seem to be correct.
I have my app scripted so that images are downloaded from my server to
"file:///storage/emulated/0/Android/data//files/images/".
I have a static index page with a content DIV, modified using jquery:
$("#rBody").html('<div class="row"><div class="col s12">'+jxml+"</div></div>");
Therefore, content is dynamically loaded. the IMG tag src path property is modified as per platform:
jxml=jxml.replace("images", app.getStorageLocation()+"files/images");
However, the image placeholders just have a blank square instead as if image is not found.
Is there any reason for this to occur? Is there a permissions property somewhere I need to enable?
Thank you for any advice!
You will need both file permissions and the File API plugin for Cordova.
With these you should be able to read the image in and add it to the tags.

How can I load resourcesting

I am using XE7 Rad Studio to build "apps" for Android and IPhone. Focusing on Android for the moment.
According to the requirements, I need to load the HTML inside the application as a resource string.
WebBrowser1.LoadFromStrings(ResourceStrings.HTMLString,'');
//Loads the resource-string successfully.
However in this resource-string I need to load images, and I cant figure out how to do it. I can see in deployment that I have the images loaded into the project {Bitmap_1, Bitmap_2,Bitmap_3}.
How do I complete this line:
resource-string:
...'<img id="img2" class="thumbnail" src="/images/im2.bmp" alt="/images/im2.bmp"/>'...
Many thanks.
If you read the documentation for LoadFromStrings(), it says:
Displays HTML string content within the TWebBrowser component.
This method uses the following parameters:
Content: specifies the HTML string to be displayed.
BaseUrl: specifies a path that is used to resolve relative URLs within the loaded page. To clarify, consider the following scenario: this parameter is set to www.mycompany.com/departments/, and the loaded page defines a link <a href=’Sales.html’>Sales dept</a>. In the given case, clicking this link opens http:// www.mycompany.com/departments/Sales.html.
That is the exact scenario you are running into. Your HTML contains relative links to external images, but you are not providing a BaseURL, so the WebBrowser cannot resolve the correct URLs it needs to load those images.
In the Deployment Manager, set the Remote Path of your image files to either StartUp/Documents/images/ or StartUp/Library/Application Support/images/.
At app startup, Delphi will copy files beginning with StartUp to the appropriate folder on the device. Then you can do the following when calling LoadFromStrings():
// note sure which function to use for 'StartUp/Library/Application Support/',
// maybe TPath.GetLibraryPath()? This example is for '/StartUp/Documents/'...
WebBrowser1.LoadFromStrings(ResourceStrings.HTMLString, 'file://' + TPath.GetDocumentsPath);
That will allow "/images/im2.bmp" to resolve to something like file:///data/data/<application ID>/files/images/im2.bmp", etc.

Why is WebView unable to open some local URLs (Android)?

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

Categories

Resources