0

I need to create a TextView and link it to an image from sdcard. So when user taps on it, it will open up the image. I used the following code, but it does not work:

TextView tv = new TextView();
tv.setAutoLinkMask(Linkify.WEB_URLS);
tv.setAutoLinkMask(Html.fromHtml("<a href=\"file:///sdcard/PIC_20150721_- 1_1245263.jpg\">PIC_20150721_-1_1245263.jpg</a>"));
tv.setMovementMethod(LinkMovementMethod.getInstance());

The problems I have so far: On screen, it does show PIC_20150721_1245263.jpg, but it display the text like this: PIC_20150721_-1_1245263.jpg, and only 1245263.jpg is clickable. It does not show the whole file name as clickable. And when I click it, it opens us chrome with URL as: 1245263.jpg and then says not able to find such page.

How to make it support file://xxxx format?

Thanks

Krishna Kachhela
  • 773
  • 1
  • 7
  • 24

1 Answers1

0

Refer to the following link and use Linkify class like this:

TextView tv = new TextView();
tv.setAutoLinkMask(Linkify.WEB_URLS);
tv.setAutoLinkMask(Html.fromHtml("<a href=\"file:///sdcard/PIC_20150721_- 1_1245263.jpg\">PIC_20150721_-1_1245263.jpg</a>"));
tv.setMovementMethod(LinkMovementMethod.getInstance());
Linkify.addLinks(tv, Linkify.ALL);