html and activity links in TextView

So we need to linkify a TextView.


By linkify, I mean adding links to a TextView. These links could either be html links that link to a webpage, or some url that links to an Activity (launches an activity).




TextView mTextSample = (TextView) findViewById(R.id.yourTextView);
String text = "Visit my blog sherifandroid.blogspot.com or run the myactivity callback";
mTextSample.setText(text);

Pattern pattern = Pattern.compile("sherifandroid.blogspot.com");
Linkify.addLinks(mTextSample, pattern, "http://");
Pattern pattern2 = Pattern.compile("myactivity");
Linkify.addLinks(mTextSample, pattern2, "sherif-activity://");

Now, the first pattern with the html link to my blogger page will work correctly.

However the second part should startActivity myactivity.
It will not work unless we specify that sherif-activity://myactivity is a callback url for an activity of our package.

So, for this to work and call say TestActivity!
Your TestActivity in AndroidManifest.xml should look like this:

<activity
	android:label="@string/app_name"
	android:name=".TestActivity">
	<intent-filter>
		<data android:host="myactivity" android:scheme="sherif-activity" />
		<action android:name="android.intent.action.VIEW" />
		<category android:name="android.intent.category.DEFAULT" />
		<category android:name="android.intent.category.BROWSABLE" />
	</intent-filter>
 </activity>

Congradulations, you just created a link to your website and to your activity in the same TextView.

How about sending some data to the new activity using the link!?

Lets first investigate the other way of linkifying a TextView. This would be using normal html tags, namely the <a> tag.


TextView mTextSample = (TextView) findViewById(R.id.yourTextView);
String text = "Visit my blog <a href=\"http://sherifandroid.blogspot.com/\">mysite</a> or run the <a href=\"sherif-activity://myactivity\">myactivity</a> callback";
mTextSample.setText(Html.fromHtml(text));
mTextSample.setMovementMethod(LinkMovementMethod.getInstance());

This will work perfectly like the previous approach.

Now, let us add some data to the link and ultimately the intent that will open the new activity.
We will use the normal GET parameters to add data.

so will will comment out one line of code which initializes text and change it so some data is added to linked activity.


String text = "Visit my blog <a href=\"http://sherifandroid.blogspot.com/\">mysite</a> or run the <a href=\"sherif-activity://myactivity?author=sherif&nick=king\">myactivity</a> callback";
//String text = "Visit my blog <a href=\"http://sherifandroid.blogspot.com/\">mysite</a> or run the <a href=\"sherif-activity://myactivity\">myactivity</a> callback";

So How can we retrieve these extra parameters in the TestActivity!? In this case, the parameter author and nick
It is rather simple:


String author = getIntent().getData().getQueryParameter("author");
String nick = getIntent().getData().getQueryParameter("nick");


Click here for Sample Project + Source Code (download) 

165 comments:

  1. Thank You So Much..and the update to call activity with parameters made my day..!!

    ReplyDelete
    Replies
    1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from HTML5 CSS3 Javascript Online Training from India . or learn thru HTML5 CSS3 Javascript Online Training from India. Nowadays JavaScript has tons of job opportunities on various vertical industry. HTML5 CSS3 Javascript Online Training from India

      Delete
  2. thank Sherif elKhatib! It work perfectly! :)

    ReplyDelete
  3. This is works great.. thank you

    ReplyDelete
  4. Check out for working example using tag

    http://javatechig.com/2013/04/07/how-to-display-html-in-android-view/

    ReplyDelete
  5. Thanks! This is help for me

    ReplyDelete
  6. I found this as an informative and interesting post,

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. However nothing of it will be possible if there were not PSD to HTML slicing possibilities. The construction of great buildings, begin with laying down the very basic singular brick in the foundation.
    StartPoint Hastings

    ReplyDelete
  10. It is extremely affordable to invest in an Android based system. Besides, you can get an experienced Android application developer at cost effective rates. Download game killer

    ReplyDelete
  11. Nice information Regarding htmls and links in text view My sincere thanks for sharing this post and please continue to share this kind of post
    Android Training in Chennai

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.
    Android Online Training

    ReplyDelete
  14. really nice blog has been shared by you.. before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blogs.
    android training in chennai

    ReplyDelete
  15. Thank you so much for your blog. I have been using it as reference for my students during Android Course in Chennai. It has been so much useful, keep writing more


    Android Training in Chennai

    ReplyDelete
  16. really nice blog has been shared by you. before i read this blog i didn't have any knowledge about this. but now i got some knowledge about this. so keep on sharing such kind of an interesting blogs.
    android training in chennai

    ReplyDelete
  17. Its an amazing article that you share about PSD To HTML conversion. Thank you so much.

    ReplyDelete
  18. Android 3 Apps is other free utility to create an android application for your Android gadgets of your choice.
    Freedom Apk

    ReplyDelete
  19. Based on your requirement, you should hire an experienced Android app developer to create innovative applications for your company.
    Download Game Killer Apk

    ReplyDelete
  20. as it needs to mull over a much lower assortment of gadgets when contrasted with Android. read this

    ReplyDelete
  21. You have provided an nice article, Thank you very much for this one. And i hope this will be useful for many people.. and i am waiting for your next post keep on updating these kinds of knowledgeable things...
    Android Training In Gurgaon

    ReplyDelete
  22. Thank you a lot for providing individuals with a very spectacular possibility to read critical reviews from this site.
    data-science-training-in-bangalore

    ReplyDelete
  23. In 1876 Thomas Edison invented a machine that ultimately became the tattoo machine, but it took modifications by Samuel O'Reilly in 1891 to adapt the device for tattooing.

    kit tattoo

    ReplyDelete
  24. Keeping in mind, the importance of mobile application and its usability, you can either choose Android or iOS. ShowBox APK

    ReplyDelete
  25. Thank you so much for sharing this amazing article with us.Will stay connected with your blogs for the future posts.
    Summer Courses for Business Administration in Chennai | Best Summer Courses in Porur

    ReplyDelete
  26. I hope these stuffs on Sites To Create Your Own Android Application for Free will help you making your own Android apps and share to your friend and entire world & most important making money through Android Apps.
    Custom Software Development Company

    ReplyDelete
  27. I talked about link value last year but I thought I'd go a few steps further and add to that, covering how Google values links nowadays when link building isn't the center of attention or the entire game that it once was.
    free custom url shortener

    ReplyDelete
  28. The information you have here is really useful to make my knowledge good. It is truly supportive for us and I have accumulated some essential data from this blog.
    Best cloud Computing Training Institute in Chennai | Best cloud Computing Training Institute in Velachery

    ReplyDelete
  29. Nice blog. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Best Microsoft Azure Training Institute in Chennai | Best Microsoft Azure Training Institute in Velachery

    ReplyDelete
  30. I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    Hadoop course in Marathahalli Bangalore
    DevOps course in Marathahalli Bangalore
    Blockchain course in Marathahalli Bangalore
    Python course in Marathahalli Bangalore
    Power Bi course in Marathahalli Bangalore

    ReplyDelete
  31. I was surfing net and fortunately came across this site and found very interesting stuff here. Its really fun to read. I enjoyed a lot. Thanks for sharing this wonderful information. vpn

    ReplyDelete
  32. Just pure brilliance from you here. I have never expected something less than this from you and you have not disappointed me at all. I suppose you will keep the quality work going on. https://internetprivatsphare.de/dazn/

    ReplyDelete
  33. This book gives you step wise extensive guide along with three golden lessons that helps your kids learn all the right things about survival die besten vpn

    ReplyDelete
  34. Really it was an awesome article… very interesting to read…Thanks for sharing.........

    pacetechnosoft
    Technology

    ReplyDelete
  35. definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog! vpnveteran

    ReplyDelete
  36. Bored of sitting at home? Play casino and get paid for it perfect popular online casinos Play and win.

    ReplyDelete
  37. Make a lot of money with online casino BGAOC we have top rated online casinos If you want to always be in the money, then try to play online casino with us.

    ReplyDelete
  38. Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
    Java Training in Chennai
    Java course in Chennai
    Hadoop Training in Chennai
    Python Training in Chennai
    Java Training in Porur
    Java Training in Adyar
    Java Training in Tnagar

    ReplyDelete
  39. In the beginning, I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips. I like your writing style and I hope you will keep doing this good working.
    Hacking Course in Chennai
    Hacking Classes in Chennai
    AWS Training in Chennai
    Data Science Course in Chennai
    Digital Marketing Course in Chennai
    Hacking Training in Tambaram
    Hacking Training in Velachery
    Hacking Training in OMR

    ReplyDelete
  40. Знаю где продается отличная rgb лента, покупал у них недавно, нареканий нет, компания называется Ekodio

    ReplyDelete
  41. Imagine yesterday went to some online casino copacetic best online gambling real money and decided to ponastalgirovat. so many pleasant memories when you again see this slot machine mmm cool

    ReplyDelete
  42. so many pleasant memories when you again see this slot machine mmm cool taxiwala movie review

    ReplyDelete
  43. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    mobile service centre chennai
    best mobile service center in chennai
    best mobile service center in chennai
    mobile service center in velacherry

    ReplyDelete
  44. Our services are available in all cities of Minneapolis and its surroundings. We are having years of experience which enabled our customers and clients to trust our services. internetprivatsphare.at

    ReplyDelete
  45. Thanks for sharing this valuable information and we collected some information from this blog.
    Android Training in Noida

    ReplyDelete
  46. Great post full of useful tips! My site is fairly new and I am also having a hard time getting my readers to leave comments. Analytics shows they are coming to the site but I have a feeling “nobody wants to be first”. lemigliorivpn.com

    ReplyDelete
  47. Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
    Thanks & Regards,
    VRIT Professionals,
    No.1 Leading Web Designing Training Institute In Chennai.

    And also those who are looking for
    Web Designing Training Institute in Chennai
    SEO Training Institute in Chennai
    Photoshop Training Institute in Chennai
    PHP & Mysql Training Institute in Chennai
    Android Training Institute in Chennai

    ReplyDelete
  48. Apex Packs as you can likewise get zenith packs just by playing the amusement all things considered with the expectation of complimentary you can get this for genuine cash as well so this can be utilized to get skins like amazing skins, Epic Skins, Rare Skins and Common Skins, these skins cost 1,200,400,60 and 30 individually.

    https://community.act.com/t5/user/viewprofilepage/user-id/64039

    ReplyDelete
  49. Happy fathers day wishes is here. Just copy and send it to your father...

    ReplyDelete
  50. Really very happy to say that your post is very interesting. I never stop myself to say something about it. You did a great job. Keep it up.
    We have an excellent IT courses training institute in Hyderabad. We are offering a number of courses that are very trendy in the IT industry. For further information, please once go through our site.
    AWS Training In Hyderabad

    ReplyDelete
  51. This is really too useful and have more ideas from yours. keep sharing many things and thanks for sharing the information.

    Best python training institute in Kanchipuram

    ReplyDelete
  52. Nice post... Really you are done a wonderful job. Thanks for sharing such wonderful information with us. Please keep on updating...

    Best Java Training Academy in Kanchipuram

    ReplyDelete
  53. Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
    data science courses training

    ReplyDelete
  54. Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
    mobile app development agency in usa

    ReplyDelete
  55. Going to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time.

    Big Data Course

    ReplyDelete
  56. I just got to this amazing site not long ago. I was actually captured with the piece of resources you have got here. Big thumbs up for making such wonderful blog page!data science course in dubai

    ReplyDelete
  57. Thanks for this greatful information. all this information is very important to all the users and can be used good at all this process
    Best Tally ERP 9.0 Training Academy in Kanchipuram

    ReplyDelete
  58. Mmm.. good to be here in your article or post, whatever, I think I should also work hard for my own website like I see some good and updated working in your site.
    Data Science Course in Pune

    ReplyDelete
  59. Nice information, valuable and excellent design, as share good stuff with good ideas and concepts, lots of great information and inspiration, both of which I need, thanks to offer such a helpful information here.data science course in dubai

    ReplyDelete
  60. Really I Appreciate The Effort You Made To Share The Knowledge. This Is Really A Great Stuff For Sharing. Keep It Up . Thanks ForQuality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing. data science course in singapore

    ReplyDelete
  61. I have read your blog its very attractive and impressive. I like it your blog.
    Best Software Testing Training Academy in Kanchipuram

    ReplyDelete
  62. thank u so much for sharing informative article, love it , read it three time, amazing.
    top 7 best washing machine
    www.technewworld.in

    ReplyDelete
  63. Thanks for sharing this post.
    Want to make your own website!!!
    Contact ACIL the best web design company in Delhi.
    WEB DESIGN COMPANY IN DELHI


    Thanks for sharing this post.
    Interested in Graphic Designing Course!!!
    Contact ACIL for the best Graphic designing Institute in Gurgaon.
    GRAPHIC DESIGNING INSTITUTE IN GURGAON



    Thanks for sharing this post.
    Interested in Python training!!!
    Contact ACIL for the best Python Training Institute in Gurgaon.
    PYTHON TRAINING INSTITUTE IN GURGAON



    ReplyDelete
  64. Your article was so impressive and informative. Its very interesting to read. Thanks for sharing,
    Best web design Training Institute in Kanchipuram

    ReplyDelete
  65. I love the way you write and share your niche! Very interesting and different! Keep it coming!

    state employee cashless treatment scheme

    ReplyDelete

  66. I am looking for and I love to post a comment that "The content of your post is awesome" Great work!
    www.technewworld.in
    How to Start A blog 2019
    Eid AL ADHA

    ReplyDelete
  67. Pretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I’ll be subscribing to your feed and I hope you post again soon.
    Data Science Courses

    ReplyDelete
  68. Just stumbled across your blog and was instantly amazed with all the useful information that is on it. Great post, just what i was looking for and i am looking forward to reading your other posts soon!

    ReactJS Online Training

    ReplyDelete
  69. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Best web Designing Training Training Institute in Kanchipuram

    ReplyDelete
  70. I finally found great post here.I will get back here. I just added your blog to my bookmark sites. thanks.Quality posts is the crucial to invite the visitors to visit the web page, that's what this web page is providing.
    AI learning course malaysia

    ReplyDelete
  71. Awesome blog thanks for sharing While choosing your perfect ride for driving, Accord Cars comes with and the best packages for you to pick from. Self drive cars in Chennai are done the easier. Just pick out your plan from hourly, daily, weekly and even monthly plans available.

    ReplyDelete
  72. Very useful blog thanks for sharing At Pearl’s - The best Bridal Makeup Parlour in Chennai, we take personal responsibility in making sure that you look as flawless and beautiful and the marriage that you have been dreaming of. With around 16,000 successful brides in our books, you can be confident that we know our art intimately and deep.

    ReplyDelete
  73. Great blog thanks for sharing Looking for the best creative agency to fuel new brand ideas? Adhuntt Media is not just a digital marketing company in chennai. We specialize in revamping your brand identity to drive in best traffic that converts.

    ReplyDelete
  74. Nice blog thanks for sharing Is this a special day for you? Beautiful and fragrant flowers are sure to make it even more amazing of a day no doubt. This is why Karuna Nursery Gardens offers you the best rental plants in Chennai that too at drop dead prices.

    ReplyDelete
  75. Excellent blog thanks for sharing Pixies Beauty Shop is unlike any of the other cosmetic shops in Chennai. With tons of exclusive imported brands to choose from and the best value, this is the best shopping destination for your personal and salon needs.

    ReplyDelete
  76. Buydankvapeonline.com Vapes has been established by a team of avid vapers, which is why we know how to meet our customers’ specific needs. We take great pains to make our assortment as varied as possible. So that you can find all sought of devices and vape supplies under one roof. You no longer have to stray through the mazes of the Internet to get vape carts online. We have all of these and even more at very cheap prices
    Are you wondering where to get vape supplies online that will make your buy dank vape experience like no other? .Simply browse through our catalog and let buydankvapeonline’s Vapes exceed your expectations. At our store, you can buy dank vapes online, buy stiizy carts online, buy kingpens online, buy wholesale carts online, buy brass knuckles online at a click. Simply search by the device type or brand and then add the product that fits the bill to your cart. We will deliver it to you in no time so that you can enjoy your favorite clouds of vapor as soon as possible
    buy vape carts online
    buy dank vapes online
    buy stiizy carts online
    buy kingpens online
    buy wholesale carts online
    buy brass knuckles online
    buy Dank Vapes now
    buy KingPen online now
    where to buy dank vape online
    buy wholesale carts online now
    dank vape store

    ReplyDelete

  77. thanks for your information really good and very nice web design company in velachery

    ReplyDelete
  78. The particular online life sites today are flooding with recommendations on the best fashion blogs to seek after. The best thing about truly attempting to comprehend and tips from electronic long range interpersonal communication is that a grouping of people recommend which ones to seek after: enormous names, fashion models, beauticians, engineers and even basically standard people. latest fashion

    ReplyDelete
  79. You can go live or free chat with lovely girls or boys in a single swipe apps like Me2call4u. You can also find new friends and also make new friends who suit your taste. Video calling app

    ReplyDelete
  80. Excellent Blog. I really want to admire the quality of this post. I like the way of your presentation of ideas, views and valuable content. No doubt you are doing great work. I’ll be waiting for your next post. Thanks .Keep it up web design company in velachery

    ReplyDelete
  81. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    web designing classes in chennai | web designing training institute in chennai
    web designing and development course in chennai | web designing courses in Chennai
    best institute for web designing in chennai | web designing course with placement in chennai
    Web Designing Class
    web designing course
    best institute for web designing

    ReplyDelete
  82. Nice blog. Thanks for sharing your programming knowledge. For more updates about latest technology, please visit cognex technology

    ReplyDelete
  83. Aluminium Composite Panel or ACP Sheet is used for building exteriors, interior applications, and signage. They are durable, easy to maintain & cost-effective with different colour variants.

    ReplyDelete

  84. Erectile dysfunction is a condition where a man is not able to get an erection. Even if they are able to get an erection, it does not last for too long. Suffering from erectile dysfunction can affect the person both physically and mentally. Therefore a person needs to take medical help to make the condition better. Also suffering from erectile dysfunction can affect the relation of the person with their partners. The medication that has brought about a wave of change in this field is the use of Viagra for erectile dysfunction. It works by targeting the basic cause of the issue thus helping millions of men all across the world. If you are a man who has been facing an issue with getting and maintaining an erection for a long time now, then you should
    .Buy Viagra online

    ReplyDelete
  85. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    web designing classes in chennai | web designing training institute in chennai
    web designing and development course in chennai | web designing courses in Chennai
    best institute for web designing in chennai | web designing course with placement in chennai
    Web Designing Class
    web designing course
    best institute for web designing

    ReplyDelete
  86. Thanks for sharing an informative blog keep rocking bring more details.I like the helpful info you provide in your articles. I’ll bookmark your weblog and check again here regularly. I am quite sure I will learn much new stuff right here! Good luck for the next!
    web designing classes in chennai | web designing training institute in chennai
    web designing and development course in chennai | web designing courses in Chennai
    best institute for web designing in chennai | web designing course with placement in chennai
    Web Designing Class
    web designing course
    best institute for web designing
    website design course | Web designing course in Chennai

    ReplyDelete
  87. Buy vape carts from us, We offer a complete and concise list of Dank Vapes, kingpen, mario carts,dank vapes flavors exotic carts, dank woods blunt and Other Vape Carts and THC Oil. Our oils are lab tested, all to ensure you get the best quality products available in the market. With our Online Dispensary services in the US, you can have your order delivered to your doorstep! Hit us up for help finding the perfect cannabis oil for you! You can equally buy Dank Vapes and Exotic Cartridges from our partner sites Vapes and Cannabis Oil Shop.You can link up at https://www.thcvapesdispensary.com

    ReplyDelete
  88. Thanks for sharing information with us.This post is very attractive and useful for the users.The content provided is relevant to the topic.One can gain knowledge and have basic understanding by reading this blog.
    data science training institutes in bangalore

    ReplyDelete