I am making my first app, and there I have photos I want the user could make them bigger with a "zoom effect".
I have been searching about it in the web and I have found I must use a webview which can do that automatically.
But the image doesn't appear. I only can watch his route as a text: "file:///storage/sdcard0/postals/4249.jpg"
And it doesn't matter if I include "file://" or not.
Here it is the code. I hope anyone of you could help me.
"Ivpostal" is the name of my webview. And "adrecafoto" is an string with the route of the image in the galery of the phone:
**uriruta=Uri.parse(adrecafoto);
Cursor c = getContentResolver().query(uriruta,null,null,null,null);
c.moveToNext();
String filePath = "";
String[] column = { MediaStore.Images.Media.DATA };
int columnIndex = c.getColumnIndex(column[0]);
if (c.moveToFirst()) {
filePath = c.getString(columnIndex);
}
c.close();
String rutafoto= "file://"+filePath;
ivpostal.loadData(rutafoto, "text/html","utf-8");**
Related
I'm building a Custom Control (a Gallery Picture Picker)
basically trying to re-make a this : Microsoft.Maui.Media.MediaPicker.PickPhotoAsync()
but i didn't find anyway to retrieve user pictures on MAUI ..
on Xamarin.Android i used this code :
var uriExternal = MediaStore.Images.Media.ExternalContentUri;
string[] projection = { (MediaStore.Images.Media.InterfaceConsts.Id),
(MediaStore.Images.Media.InterfaceConsts.DateAdded),
(MediaStore.Images.Media.InterfaceConsts.RelativePath) };
var cursor = Android.App.Application.Context.ContentResolver.Query(uriExternal, projection, null, null, MediaStore.Images.Media.InterfaceConsts.DateAdded);
if (cursor != null) {
int columnIndexID = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Id);
int RelativePathID = cursor.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.RelativePath);
while (cursor.MoveToNext()) {
long imageId = cursor.GetLong(columnIndexID);
string rPath = cursor.GetString(RelativePathID);
//Get the Picture's URI
Android.Net.Uri uriImage = Android.Net.Uri.WithAppendedPath(uriExternal, "" + imageId);
...
}
}
with this Code, given the required permissions, i could get the external path of all pictures of an Android phone to then use them in my PicturePicking custom control ..
==> how can i do this in Microsoft MAUI !! (targeting Android & IOS)
(just to be clear, of course i know that i could just use MediaPicker's [PickPhotoAsync] function, but i clearly don't want that, it's not an option)
Thanks in advance for any help !
So after 2 days of searching.. i've came to the conclusion that the only way to do this is by using Plateform Specific Code ..
(i tryed it successfully)
I have a Link which never changes. The only thing which changes is the file name (in bold). so how do I get the file name from this link? I want to display this in a textview or toast-
http://apkins.aptoide.com/aptoide-8.1.0.1.apk?=x
Here is a regex-less solution:
public static String getFileName(String link) {
int endIndex = link.lastIndexOf('?');
return link.substring(26, endIndex);
}
It's pretty simple. It first gets where the file name ends i.e. the position of the last "?". Then it "cuts out" a new string from the link starting from the 27th character to the end of the file name.
This should do the trick
String fileName = url.substring(url.lastIndexOf('/') + 1);
You can also try URLUtil.guessFileName(url, null, null)
Edit 1
String url = "any url"
String given = "http://apkins.aptoide.com/aptoide-8.1.0.1.apk?=x";
String extractedAppName = given.substring(given.lastIndexOf("/") + 1, given.lastIndexOf("?"));
This should work. It takes the position of the / before the name and then the position of the ?. It takes the string (substring) between those two characters. Just give it a try and you'll see.
I want to get all the browser history records from different browsers in android mobile phone ?(Maybe as you know, there are usually more than one browser apps in a phone ).Is there anyone has done this successfully and give me a hint ? Example code is preferred.Any help will be helpful.. Thanks a lot in advance ! :)
Just look at this. I used it in my code and I am getting browser history through it(Default Browser).
String[] proj = new String[] { Browser.BookmarkColumns.TITLE, Browser.BookmarkColumns.URL };
String selection = Browser.BookmarkColumns.BOOKMARK + " = 0"; // 0 = history, 1 = bookmark
mCursor = this.managedQuery(Browser.BOOKMARKS_URI, proj, selection, null, null);
this.startManagingCursor(mCursor);
mCursor.moveToFirst();
String title = "";
String url = "";
if (mCursor.moveToFirst() && mCursor.getCount() > 0) {
while (mCursor.isAfterLast() == false && cont) {
title = mCursor.getString(mCursor.getColumnIndex(Browser.BookmarkColumns.TITLE));
url = mCursor.getString(mCursor.getColumnIndex(Browser.BookmarkColumns.URL));
// Do something with title and url
mCursor.moveToNext();
}
}
Hope this helps you.
Limitations :
Browser.BOOKMARKS_URI will, at most, work for the open source Browser app that is part of the Android Open Source Project. Device manufacturers are welcome to replace that app with something else that will not be recording its history, bookmarks, or anything else in that ContentProvider. Similarly, users are allowed to download third-party browsers, which may not be storing things in that ContentProvider.
I'm attempting to download webpages for a user to view later. So far, I've downloaded the html, and the images. I can get the HTML to show up nicely formatted, but I cannot get the images to inline.
The code I'm using so far:
This is my method to get the article.
MyImageGetter mig = new MyImageGetter(this, urlId);
Spanned span = Html.fromHtml(contents[1], mig, null);
contents[1] = span.toString();
titleView.setText(contents[0]);
content.setText(contents[1]);
contents[] is an array that contains two strings. contents[0] is a simple string, contents[1] is a string with HTML markup.
MyImageGetter:
public class MyImageGetter implements Html.ImageGetter{
String urlId = null;
Context c = null;
public MyImageGetter(ArticleViewer articleViewer, String urlId2) {
c = articleViewer;
urlId = urlId2;
}
public Drawable getDrawable(String source) {
String[] brokenUrl = source.split("/");
String imgName = brokenUrl[brokenUrl.length-1];
File image = new File("/data/data/com.theHoloDev.Reader/Offline/" + urlId + "/" + imgName);
Log.w("MyApp", image.getAbsolutePath());
Bitmap bm = BitmapFactory.decodeFile(image.getAbsolutePath());
Drawable d = new BitmapDrawable(c.getResources(), bm);
return d;
}
}
When I have it log image.getAbsolutePath() it comes up with a file that exists in ddms. The Text content is there perfectly, but there are still little black boxes that say obj in each image. I had thought a textview would still be able to display images in that fashion, but either I'm doing something wrong, or there is another way to do this.
What is your desired end result? It is confusing to see that you are displaying html but you want the user to see the page... without html or did you do that for debugging? I assume the users will not see the html but rather the the page itself. In this case, I would go for a webview.
http://developer.android.com/reference/android/webkit/WebView.html
I don't think the text view is meant to be used like you are using it.
Good luck.
I figured it out. Instead of:
Spanned span = Html.fromHtml(contents[1], mig, null);
contents[1] = span.toString();
content.setText(contents[1]);
I need:
Spanned span = Html.fromHtml(contents[1], mig, null);
content.setText(span);
I was running into problems setting span to string.
just a quick question. how do you get thumbnail images from an sdcard on HTC Desire HD. i have this code but it just shows a blank screen and a scroll. the images can be chosen but as i say, you can't see anything.
String [] img = {MediaStore.Images.Thumbnails._ID};
imageCursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, null, null, MediaStore.Images.Thumbnails._ID);
image_column_index = imageCursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
if(imageCursor != null && imageCursor.moveToNext()) {
grid = (GridView)findViewById(R.id.gridview);
grid.setAdapter(new ImageAdapter(getApplicationContext()));
grid.setOnItemClickListener(this);
}
Here is the piece of code where its coming from. Any ideas what i can be doing wrong?.. by the way, the working on other devices like the G-1. Thank you.