如何从Android应用程序中隐藏Google Chrome中的网页

GvS*_*rma 7 java android google-chrome

我花了很多时间在这上面并且无法弄清楚这一点.

我需要以隐身模式启动Chrome浏览器.

我的代码:

    private void launchBrowser() {
    String url = "http://foyr.com";
    Intent launchGoogleChrome = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    launchGoogleChrome.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchGoogleChrome.setPackage("com.android.chrome");
    try {
        startActivity(launchGoogleChrome);
    } catch (ActivityNotFoundException e) {
        launchGoogleChrome.setPackage(null);
        startActivity(launchGoogleChrome);
    }
}
Run Code Online (Sandbox Code Playgroud)

我发现了几个帖子,但无法找到解决方案. 这里

这个链接给了我一些关于隐身模式的想法,但我也试过这个.

    private void launchBrowser() {
    String url = "http://foyr.com";
    Intent launchGoogleChrome = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    launchGoogleChrome.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    launchGoogleChrome.setPackage("com.android.chrome");
    launchGoogleChrome.putExtra("com.android.chrome.EXTRA_OPEN_NEW_INCOGNITO_TAB", true);
    try {
        startActivity(launchGoogleChrome);
    } catch (ActivityNotFoundException e) {
        launchGoogleChrome.setPackage(null);
        startActivity(launchGoogleChrome);
    }
}
Run Code Online (Sandbox Code Playgroud)

但Chrome浏览器没有从应用程序接收任何意图信息.任何人都可以帮助我哪里出错了,该怎么办?

小智 4

从源代码来看:

// "Open new incognito tab" is currently limited to Chrome or first parties.
if (!isInternal
        && IntentUtils.safeGetBooleanExtra(
                   intent, EXTRA_OPEN_NEW_INCOGNITO_TAB, false)) {
    return true;
}
Run Code Online (Sandbox Code Playgroud)

除非您分叉 Chrome 或 Google 明确允许,否则额外的内容似乎没有任何作用。