简体   繁体   中英

Opening a URL in Android's web browser from my application?

Opening a URL in Android's web browser from my application? I tried this:

 try {
        Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(download_link));
        startActivity(myIntent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, "No application can handle this request."
            + " Please install a webbrowser",  Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                Uri.parse(playStoreLink));
        startActivity(browserIntent);

you should check your link otherwise you have to show your logcate.

You can try the following:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

public void onOpenWebBrowser(View v)
{
   Intent webPageIntent = new Intent(Intent.ACTION_VIEW);
   webPageIntent.setData(Uri.parse("https://www.google.co.in/"));

   try {
      startActivity(webPageIntent);
   } catch (ActivityNotFoundException ex) {

   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM