Android打开浏览器可避免出现多个选项卡

Android打开浏览器可避免出现多个选项卡

本文介绍了Android打开浏览器可避免出现多个选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试通过服务打开浏览器窗口,该链接在浏览器的当前选项卡中打开.当我使用

I am trying to open the browser window from my service with a link that opens in the current tab of the browser. when I use

Intent intent = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
context.startActivity(intent);

如果在我的服务启动意图之前打开浏览器并在前台运行,则浏览器将在同一窗口/选项卡中打开链接.如果最小化浏览器并且服务启动了意图,则浏览器会在新窗口/选项卡中打开网页.

If the browser was opened and in the foreground before my service starts the intent and the browser opens the link in the same window/tab. If the Browser was minimized and the service starts the intent, the browser opens the webpage in a new window/tab.

我无法使用网络视图,因为它需要在网络浏览器中使用,并且只会处理默认的浏览器.我已经在在android浏览器中打开一个网址,避免使用多个标签,但没有答案.我也尝试过强制关闭浏览器,但是那也行不通.

I cannot use a web-view as it needs to be in the web browser and it will only be dealing with the default browser. I have checked out the thread at Open an url in android browser, avoid multiple tabs but it did not have an answer. I also have tried force closing the browser but that is also does not work.

谢谢您的帮助!

推荐答案

避免多个选项卡的方法如下:

The way to avoid multiple tabs is as follows:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(uri);
intent.putExtra(Browser.EXTRA_APPLICATION_ID, getPackageName());
startActivity(intent);

EXTRA_APPLICATION_ID将包含您的应用程序ID,浏览器将回收由您的应用程序打开的标签页,而不是打开新标签页.这样,您的应用程序打开的所有页面都将共享相同的标签,并且浏览器中不会出现标签膨胀"的情况.

The EXTRA_APPLICATION_ID will contain an ID of your app, and the browser will recycle a tab that was opened by your application, rather than opening a new tab. In this way, all the pages opened by your application will share the same tab, and you will not have "tab inflation" in the browser.

这篇关于Android打开浏览器可避免出现多个选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:42