Menus

Showing posts with label How to open a website when a Button is clicked in Android application. Show all posts
Showing posts with label How to open a website when a Button is clicked in Android application. Show all posts

Monday 25 November 2019

How to open website by clicking a button in android


You can use this on your button click activity


Intent myLink = new Intent(Intent.ACTION_VIEW);
myLink.setData(Uri.parse("http://yii2ideas.blogspot.com/p/blog-page.html"));
startActivity(myLink);



and import this on your code


import android.net.Uri;














Error Problem



Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?



Solutions to add - FLAG_ACTIVITY_NEW_TASK flag to your intent:


Intent myLink = new Intent(Intent.ACTION_VIEW);
myWebLink.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myLink.setData(Uri.parse("http://yii2ideas.blogspot.com/p/blog-page.html")); startActivity(myLink);