Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open a web page in Google chrome incognito from android app

I have spent much time on this and unable to figured out about this.

I need to launch chrome browser in incognito mode.

My Code:

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

i found several posts on this but am unable to find the solution. here

This link gives me some idea about incognito mode but i tried this also.

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

But chrome browser is not receiving any intent info from app. can any one help me where am wrong and what to do?

like image 817
GvSharma Avatar asked Jun 08 '16 07:06

GvSharma


People also ask

How do I set Chrome to open links in incognito?

You can also use a keyboard shortcut to open an Incognito window: Windows, Linux, or Chrome OS: Press Ctrl + Shift + n. Mac: Press ⌘ + Shift + n.

How do I make Android incognito open automatically?

To do so, tap and hold on the Chrome icon from the home screen or your device's app drawer. This will open an overlay menu, then, tap and hold the 'New Incognito tab' tile and drag it across your screen.


1 Answers

From the source code :

// "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;
}

It seems the extra will do nothing unless you are forking Chrome or explicitly allowed to by Google.

like image 186
Geompse Avatar answered Oct 04 '22 02:10

Geompse