简体   繁体   English

使用默认主页启动 Chrome(不是 about:blank)

[英]Launch Chrome with default home page (not about:blank)

All examples i can find are intented to open a specific internet adress, but not just the Chrome browser with a new tab.我能找到的所有示例都旨在打开特定的互联网地址,而不仅仅是带有新标签的 Chrome 浏览器。 Se below screenshots for the difference between opening a "about:blank" page, and a new tab:下面是打开“about:blank”页面和新标签页区别的截图:

about:blank :关于:空白

在此处输入图片说明

New tab :新标签

在此处输入图片说明

So this is my Activity Class right now:所以这是我现在的活动类:

public void openChrome(View view) {
        String url = "http://www.stackoverflow.com";
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(url));
        startActivity(i);
    }

How do i ONLY launch the chrome app (so i return to the previous session), OR open it with a blank "new tab" page?我如何只启动 chrome 应用程序(所以我返回到上一个会话),或者用一个空白的“新标签”页面打开它? Is there any way to do that?有没有办法做到这一点?

UPD : Since what you're aiming at is not a plain "about:blank" page, what might've worked for you is either chrome://newtab or chrome://new-tab-page (as can be seen in chrome://about). UPD :由于您的目标不是简单的“about:blank”页面,因此可能对您chrome://newtabchrome://newtabchrome://new-tab-page (如在铬://关于)。 If both crash the app, then I'd consider it a bug.如果两者都使应用程序崩溃,那么我会认为这是一个错误。

For plain blank tab use special about:blank as url.对于普通的空白选项卡,请使用特殊的about:blank作为 url。

Put the url of search engine that you want.输入你想要的搜索引擎的网址。

String url = "https://google.com"; //In My case Google

Or this to launch chrome或者这个来启动chrome

Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.android.chrome");
if (launchIntent != null) { 
    startActivity(launchIntent);//null pointer check in case package name was not found
}

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

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