【问题标题】:Opening url in the last open tab in chrome在 chrome 的最后一个打开选项卡中打开 url
【发布时间】:2015-01-08 20:59:51
【问题描述】:

我在默认浏览器 (Chrome) 中打开 URL 时遇到问题

我的要求是在 Chrome 浏览器 4.4.4 的最后一个打开选项卡中打开 URL(Chrome 是默认浏览器)。不在新标签中。

以下代码在新标签页中打开 URL:

Intent mBrowserIntent = new Intent(Intent.ACTION_VIEW);
mBrowserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);                                           mBrowserIntent.putExtra(Browser.EXTRA_APPLICATION_ID,mContext.getPackageName());                    mBrowserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
mBrowserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);             
mBrowserIntent.setData(Uri.parse(mUrl));
mContext.startActivity(mBrowserIntent);

请帮忙解决这个问题。

谢谢,

【问题讨论】:

  • 同一个标签是什么意思?您是指最后一个打开的标签页吗?

标签: android google-chrome browser


【解决方案1】:

这对我有用,注意你不应该使用 getPackageName():

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://yahoo.com"));
intent.putExtra(Browser.EXTRA_APPLICATION_ID, "com.android.browser");
startActivty(intent);

编辑:我刚刚在 4.2.2 上对其进行了测试,它可以工作。

【讨论】:

  • 我正在用同样的方法在 moto g 中进行测试。它正在新标签中打开。
  • 你用过“com.android.browser”吗?
  • 我的要求是,假设我在 chrome 浏览器的一个选项卡中浏览 www.yahoo.com。我让用户不要通过在同一选项卡中打开其他网址来查看该内容
猜你喜欢
  • 2014-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多