How to open a webpage in Google chrome incognito from an Android application

I spent a lot of time on it and could not understand about it.

I need to run the Chrome browser in incognito mode.

My code is:

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 about this, but could not find a solution. here

This link gives me some insight into incognito mode, but I tried it too.

  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 the Chrome browser does not receive intent information from the application. can someone help me where am i wrong and what to do?

+5
source share
1 answer

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 that the extra will not do anything if you do not open Chrome or explicitly allow Google.

+2
source

All Articles