Matthias
Matthias

Reputation: 5764

ActionProvider to open browser

I would like to add a ShareActionProvider to my ActionBar according to this example. But I can not find any example that sets the Intent that consumes an URL/URI and opens the browser once the user clicks on the menu item.

private ShareActionProvider mShareActionProvider;
...

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu resource file.
    getMenuInflater().inflate(R.menu.share_menu, menu);

    // Locate MenuItem with ShareActionProvider
    MenuItem item = menu.findItem(R.id.menu_item_share);

    // Fetch and store ShareActionProvider
    mShareActionProvider = (ShareActionProvider) item.getActionProvider();

    // Return true to display menu
    return true;
}

// Call to update the share intent
private void setShareIntent(Intent shareIntent) {
    if (mShareActionProvider != null) {
        mShareActionProvider.setShareIntent(shareIntent);
    }
}

Upvotes: 0

Views: 75

Answers (1)

userM1433372
userM1433372

Reputation: 5507

To open an url in the browser use the following intent:

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

Is this what you want?

Upvotes: 1

Related Questions