【问题标题】:Custom menu to bookmark current url with Chrome custom tabs使用 Chrome 自定义标签为当前网址添加书签的自定义菜单
【发布时间】:2015-09-07 16:15:49
【问题描述】:

我正在试用新的 Chrome 自定义标签,并希望添加一个自定义菜单项来为显示的页面网址添加书签。我创建了一个新的待定意图来启动书签活动,但我找不到将当前页面 url 传递给书签活动的方法。这可能吗?

这就是我创建菜单项的方式:

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);
}

【问题讨论】:

    标签: android chrome-custom-tabs


    【解决方案1】:

    编辑: 自发布以来,这一点发生了变化。现在,可以检索 URL。要在 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();
        }
    }
    

    【讨论】:

    • 这就是我想要做的,为用户导航到的新网址添加书签(或共享)。我找不到通过未决意图传递新网址的方法。
    猜你喜欢
    • 2012-12-22
    • 2013-02-25
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 2022-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多