What is an image uri? Image uri inside the listview - android

Can someone please explain to me what's an image uri? I have an android app with a listview that can attach an image, and that listview displays the imag uri. thanks

URI is an address like: http://www.google.com/image.png it refers to the image somewhere.
It can also be a local address: file:////something.png
So you can attach a file that you don't have on your device and you don't want to download it.

URI or Uniform Resource Identifier is a compact sequence of characters that identifies an abstract or physical resource. It can be further classified as a locator, a name, or both.
Basically URI (in some cases URL or URN) will point to the image location, or will be the name of the image (why not both?).
Let's take a look at some URI examples:
https://stackoverflow.com/ (a URL because of the HTTPS protocol)
ftp://ftp.is.co.za/rfc/rfc1808.txt (also a URL because of the
FTP protocol)
http://www.ietf.org/rfc/rfc2396.txt (also a URL because of the
HTTP protocol)
ldap://[2001:db8::7]/c=GB?objectClass?one (also a URL because of the
protocol)
mailto:John.Doe#example.com
tel:+1-816-555-1212
telnet://192.0.2.16:80/ (also a URL because of the protocol)

Basically it's just a string in which identifies some-type of web resource.

Related

Download image from new Google+ (plus) Photos Of Gallery with Image Extension

In new android version, they have added gplus photo section in gallery.
In my application, i have incorporated the logic of selecting image from it and display to the user using below link of stackoverflow:
Download image from new Google+ (plus) Photos Application
However, i also need image extension as we are sending image raw data with extension of selected picture to the API. gplus returns the image path like this
content://com.google.android.apps.photos.content/0/https%3A%2F%2Flh5.googleusercontent.com%<a bunch of letters and numbers here>
So, how can i get extension of that image also from gplus?? Any idea??
I AM SUCCESSFULLY GETTING BITMAP FROM ABOVE URI. I JUST NEED EXTENSION OF THAT IMAGE NOW.
Thanks.
Use ContentResolver.getType(uri):
Uri uri = // your content://com.google.android.apps.photos.content URI
String mimeType = getContentResolver().getType(uri);
// mimeType will be image/png, image/jpeg, etc.

who sets the mimetype in Downloader?

In the WebView I am loading a HTML which has an anchor pointing to a location like "http://localhost:9300/sample.pdf"
I have also overriden the Downloader's onDowloadStart method.
When clicking the link, the onDowload method is called and the mimetype value is set to "application/pdf"
My question is how does Android know how to set the mime type?
Looking with Fiddler (I set it as a proxy on Android) there is no request done to the server when clicking the link.

Get mime type of content scheme

In order to send an image to a server from my android application, I have to get mime type of the image (or, at least, its extension).
I get the image from a ACTION_GET_CONTENT intent. Some applications, like Dropbox, send a file:// scheme data, so I can guess the extension using MimeTypeMap.getFileExtensionFromUrl(), but some others, like Google Drive, send a content:// scheme, which not permit to do so.
I've tried many things before posting here, like this:
AssetFileDescriptor asset = getContentResolver().openAssetFileDescriptor(getIntent().getData(), "r");
FileInputStream stream = asset.createInputStream();
String mime = URLConnection.guessContentTypeFromStream(stream); // returns null
The only workaround I think is to decode the asset into a Bitmap, then generate a new compressed image (using Bitmap.compress()), but it will add some work to the phone, and it could change the format/quality of original image, so I reserve it only if there is no other solution.
Does anyone have an idea about my problem? Thanks a lot for help ;)
As suggested by #sh3psheep on Twitter, I've tried this, and it works for content:// schemes:
Uri data = getIntent().getData();
String mime = getContentResolver().getType(data); // returns correct MIME type, such as "image/png"
The only con I found is that it does not support file:// scheme, but we can handle it using method I described in question.

Android - Reference resource drawable as a URL

I'm using an API in my Android app that downloads images from the web and shows a placeholder animation while the images are downloading (RemoteImageView, part of the Ignition package here.
At some points in the app, I need to show images from the local resource drawables and not downloaded from the web.
Is it possible to access the local resource drawables using a URL ?
The way to do it:
use this line "android.resource://[your package]/"+[res id]
Here is an example
Uri myURI = Uri.parse("android.resource://com.example.project/" + R.drawable.myimage);
for convenient you can use it as a method:
public static Uri getUrl(int res){
return Uri.parse("android.resource://com.example.project/" + res);
}
Warning do not use context.getPackageName() as substitute to package name because it might return a null value.
Local image resources do not have urls, they have URIs. So if you have image in drawable, you can parse them from resource id to URI.
Uri uri=Uri.parse("R.drawable.image");
However, if you can also put your images in asset folder of the package and access them using their URL. The URL of the image files would be "file:///android_asset/image.png"
You can use either of the option.

Opening URL on Android web browser causes Google search

I'm having a slight problem opening a certain URL in the browser. First of all I use the following code to launch the browser:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(Globals.currentChatURL));
startActivity(Intent.createChooser(browserIntent, "Select browser:"));
Now if I set Globals.currentChatURL to something like http://www.google.com then it opens that site just fine. But my URL is a little more complicated as it contains multiple parameters which are all base64 encoded. Here is an example of how my URL looks:
http://webportal.mysite.com/ChatProgram/chat.php? intgroup=UFYyMA==&intid=UFYyMEZN&hg=Pw__&pref=user&en=U0NPVFQgTUlMTEFS&ee=cGF1bGdAbWFnbmF0ZWNoLmNvbQ==&eq=UFRWRkVI&ec=TUFHTkFURUNI
Now if I use my above code to try and launch this URL it brings me to the Google search page with the following message:
"Your search - http://URLabove ... did not match any documents"
Yet if I copy the URL and paste it into the address box it brings me to the right place. How can I fix this?? The whole point of this is to have the user click the button and the site to launch, not for the user to have to copy and paste the URL manually.
Any suggestions would be greatly appreciated.
Thanks a lot
There is unwanted equal signs in the query part of your http URI. Such signs have a specific meaning as delimiters in the form &parameter=value.
This equal signs represents padding values (0, 1 or 2) from your base64 encoding.
You can either
remove them because your base64 server decoder won't bother reconstructing them, or
percent encode them (with all other reserved characters).
In android you can use percent encode this way:
String value = URLEncoder.encode("annoying values with reserved chars &=#", "utf-8");
String url = "http://stackoverflow.com/search?q=" + value;
The RFC 2396 is now deprecated but that is what URI.parse() is based on as stated by the documentation:
uriString an RFC 2396-compliant, encoded URI

Categories

Resources