简体   繁体   English

使用Chrome自定义标签将当前网址添加为书签的自定义菜单

[英]Custom menu to bookmark current url with Chrome custom tabs

I'm trying out the new Chrome custom tabs and want to add a custom menu item to bookmark the displayed page url. 我正在尝试使用新的Chrome自定义标签,并希望添加自定义菜单项以对显示的页面网址添加书签。 I create a new pending intent to launch the bookmark activity but I cannot find a way to pass the current page url to the bookmark activity. 我创建了一个新的挂起意图来启动书签活动,但是我找不到将当前页面URL传递给书签活动的方法。 Is this possible or not? 这有可能吗?

This is how I create the menu item: 这是我创建菜单项的方式:

private void prepareMenuItems(CustomTabUiBuilder uiBuilder) {
    Intent menuIntent = new Intent();
    menuIntent.setClass(getApplicationContext(), this.getClass());
    Bundle menuBundle = ActivityOptions.makeCustomAnimation(this, android.R.anim.slide_in_left,
            android.R.anim.slide_out_right).toBundle();
    PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, menuIntent, 0,
            menuBundle);
    uiBuilder.addMenuItem("Bookmark page", pi);
    menuIntent.setClass(getApplicationContext(), BookmarkActivity.class);
}

EDIT: This was changed since launch. 编辑:自启动以来已更改。 Now, it's possible to retrieve the URL. 现在,可以检索URL。 To handle the URL on the BroadcastReceiver do like this: 要处理BroadcastReceiver上的URL,请执行以下操作:

@Override
public void onReceive(Context context, Intent intent) {
    String url = intent.getDataString();
    if (url != null) {
        String toastText =
                getToastText(context, intent.getIntExtra(KEY_ACTION_SOURCE, -1), url);
        Toast.makeText(context, toastText, Toast.LENGTH_SHORT).show();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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