开发者

Android : Open a URL in a Browser [duplicate]

开发者 https://www.devze.com 2023-03-11 00:58 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: How can I open a URL in Android’s web browser from my application?
This question already has answers here: Closed 10 years ago.

Possible Duplicate:

How can I open a URL in Android’s web browser from my application?

I've been trying to find out how to create an intent that will open the specified URL in a Specified browser. Brow开发者_运维技巧ser may not always be the default one. But i am unable to do so.


Use the Intent.ACTION_VIEW constant as Intent action and the url as data.

final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
activity.startActivity(intent);

Note the URL must be a full URL (starting with either http:// or https://) so check in your code that the URL is not a short form such as www.google.com if it is user-defined.


try this :

String url = "your URL";
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);


You can use any of them, also read the Link

 Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://www.google.com")); 
startActivity(browserIntent); 

or

String url = "http://www.example.com";
 Intent i = new Intent(Intent.ACTION_VIEW); 
i.setData(Uri.parse(url)); startActivity(i); 
0

精彩评论

暂无评论...
验证码 换一张
取 消