open external link in actionBar

Asked

Viewed 59 times

-2

How do I open an external link from the Toolbar menu

I tried some solutions but n got, I marked the snippet that would 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);

    }
}

previa do app

Solution

Uri uri = Uri.parse("http://www.google.com"); // missing 'http://' will            cause crashed
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
  • 1

    Welyson, have you solved your problem? The correct thing is for you to put the problem solution as the answer to your question and not the question itself.

  • td right now.

  • I don’t adc the most exact tags doq I would like pq still don’t have lvl/reputation required, Grr @Carlosheuberger

1 answer

1


Solution

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.