open external link in actionBar

-2

How do I open an external link from the toolBar menu

I tried some solutions but I could not, I marked the section that I would like to put the click to open the link in the browser.

 public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_settings:
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("text/plain");
            share.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);

            share.putExtra(Intent.EXTRA_SUBJECT,
                    "Baixa esse aplicativo ai é muito divertido.");
            share.putExtra(Intent.EXTRA_TEXT,
                    "Baixa esse aplicativo ai!!! é muito divertido " +
                            " https://play.google.com/store/apps/details?id=meme.welyson.brasil.brasilmemes");

            startActivity(Intent.createChooser(share, "Mostrar para amigos"));
            return true;


// quero colocar o link nesse case
        case R.id.action_favorite:

            AsynchronousFileChannel window = null;
            window.open("link para abrir externamente", "_system");

            return true;

        default:
            // If we got here, the user's action was not recognized.
            // Invoke the superclass to handle it.
            return super.onOptionsItemSelected(item);

    }
}

Solution

Uriuri=Uri.parse("http://www.google.com"); // missing 'http://' will            cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
    
asked by anonymous 12.09.2017 / 04:15

1 answer

1

Solution

Uri uri = Uri.parse("http://www.google.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
    
14.09.2017 / 03:22