如何在自定义选项卡中添加共享链接菜单

时间:2016-12-16 08:37:29

标签: android android-intent chrome-custom-tabs

我正在尝试向ChromeCustomTabs添加新的菜单项以共享当前网址。

我知道我们可以添加默认

.addDefaultShareMenuItem()

到我们的CustomTabsIntent。但我不想用这个。

我也知道如何通过创建PendingIntent来添加菜单项,如: -

Intent urlIntent = new Intent();
String currentURL = urlIntent.getDataString();
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.setType("text/plain);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
PendingIntent p = PendingIntent.getActivity(getBaseContext(), 123, shareIntent, PendingIntent.FLAG_UPDATE_CURRENT);

现在,在我们的构建器中,我们将添加: -

.addMenuItem("Share Current Link", p);

代码有效,但返回空值而不是当前网址。

我不知道在Intent urlIntent = new Intent(/*what to put here to get customTabs intent*/)放什么。 我们不能将customIntent放在这里,因为它不是意图。

1 个答案:

答案 0 :(得分:0)

对不起重复的问题。在这里找到了另一个标题: -

https://stackoverflow.com/a/35651569/6823930