Android stream non static file image from URL - android

How to read an image from a URL like this in Android using ImageView:
[http://www.mphonline.com/ImgFile.aspx?TmpFile=D:\MPHLoc\ProdImg\9781740594943_s.jpg]
It would not return a normal static image stream.
Thanks.

An Android emulator could not access resource from local drive
like c: d: e: as shows in your Que: D:\MPHLoc\ProdImg\9781740594943_s.jpg
You can refer this if you want to download and display image from local

Related

Flutter how to scrape an image source element on a website

I'm trying to parse an img src that is featured on a website and include it into my app. I'm using the flutter package Web Scraper, this is the code I've tried so far:
final webScraper = WebScraper('https://tiktok.com');
if(await webScraper.loadWebPage('/#$enteredUsername')){
tiktokProfilePictureURL = webScraper.getElement('img', ['src']);
print(tiktokProfilePictureURL);
}
The image I'm trying to get the URL from is the profile picture of the account, as shown in the screenshot below.
When I look into the code of the website it provides the link to the website image but when I try to parse this in web scraper it can't seem to find it.
This is the WebScraper output:
As you can see it finds various .svg images but not the .jpeg profile picture I'm trying to find.
Or maybe there is another way to parse this image src url? Any suggestions? Thanks.

Path to Local Image Specified in JSON

I'm working with a tutorial fromRay Wenderlich (https://www.raywenderlich.com/124438/android-listview-tutorial). In the tutorial, an image is retrieved via the Internet using a URL specified in the locally stored JSON file:
"image" : "https://www.edamam.com/web-img/341/3417c234dadb687c0d3a45345e86bff4.jpg"
The string is stored in the imageUrl variable:
recipe.imageUrl = recipes.getJSONObject(i).getString("image");
Then the image is loaded using Picasso:
Picasso.with(mContext).load(recipe.imageUrl).placeholder(R.mipmap
.ic_launcher).into(thumbnailImageView);
I would like to change the code in the tutorial so that the image is retrieved from the drawable folder within the app, rather than via the Internet. I've been working on this on and off for several days. I assumed it was a matter of changing the URL in the JSON data so that it specified a path to the image file in the drawable folder like this:
"image" : "android.resource://com.raywenderlich.alltherecipes/drawable/chicken.jpg"
So far I've been unsuccessful. Am I on the right path, or am I way off? I'm an Android newbie. I'm used to working with plists in Xcode (although I'm no expert there, either).

Using webview to load image from rest server in Android

I have a rest server hosted in Amazon written in Delphi with a method returning a jpg Stream image.
I need download the image and show in webview.
The method Rest Server method is something as:
//delphi code
function TSrvServerMetodos.ImagePac(pront:integer): TStream;
var blob:TStream;
begin
...
Result := CreateBlobStream(fieldbyname('PHOTO'),bmRead);
end;
where the Result is a jpeg Stream with a image.
To access the remote rest method I am trying to use the next:
String url = Common.getServerUrl() +"/"+ "\"ImagePac\"";
String URL=url+"/"+"23";
webView.loadUrl(URL);
But no Image is showing in webview.
My image is comming from a rest server and no a website. I have no way to call something as webview.loadUrl("http://www.myserver.com/myimage.jpg");
Is possible load that image with webview?
Regards, Luiz
Yes, It is. To solve the problem I had to save the image to sdcard and create a html string to load the image with webview.
For the new offspring with the same trouble. Just encode image in base64 and place it in src attribute of img tag

Can't share image from dataDirectory via SocialSharing-PhoneGap-Plugin

I have a Cordova android project and using SocialSharing-PhoneGap-Plugin to share images
I'm storing images in dataDirectory. But when sharing image, it won't shares!
window.plugins.socialsharing.share('', 'subject', window.cordova.file.dataDirectory + 'folder/image.jpg');
Share popup appears and I can select an app, subject will share but image won't!
If I share an image from www folder, it works fine.
I used share with image data method:
window.plugins.socialsharing.share(null, 'Android filename', 'data:image/png;base64,R0lGODlhDAAMALMBAP8AAP///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUKAAEALAAAAAAMAAwAQAQZMMhJK7iY4p3nlZ8XgmNlnibXdVqolmhcRQA7', null);
Note: passing a base64 file as 'data:' is not supported on Android 2.x
You can see here how to Get base64 image data
I'm adding files/ in the final path and it works for me:
window.cordova.file.dataDirectory + 'files/folder/image.jpg'

How to open google drive public link

I have uploaded a file on google drive, i have made it public. i am able to access this on browser but not with my android app.
I need to access this public link on MY ANDROID APP.
PFB the link of file:
https://drive.google.com/file/d/0B56C1LC3IVXCV055WFIyVTZjTTA/edit?usp=docslist_api
Is this possible to access a publicly shared GD file on android app?
Code snippet is
URL url = new URL("https://drive.google.com/file/d/0B56C1LC3IVXCV055WFIyVTZjTTA/edit?usp=docslist_api");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
return bmp;
The solution is to format the address of the document you have shared.
Check this :
URL = "https://docs.google.com/uc?id=" + IDFile + "&export=download";
Your link is not to image but to Google Drive App with this image opened, real URL to image is this
Consider using Google Drive API
How about scaling the picture down to a reasonable size, it may just be that the image is too large for your heap to load
Bitmap.createScaledBitmap(Bitmap src, int Width, int Height, boolean filter)
There one other way to access file's public link By adding :
https://googledrive.com/host/[folderId]/fileName.extension
As you have provide file url
You can use that url like this for public access
https://googledrive.com/host/0B56C1LC3IVXCV055WFIyVTZjTTA
You simply need to grab the webContentLink of the newly created file.
From the documentation ...
webContentLink string
A link for downloading the content of the file in a browser using cookie based authentication. In cases where the content is shared publicly, the content can be downloaded without any credentials.

Categories

Resources