如何从Android应用程序中打开Goog​​le chrome隐身模式下的网页 [英] How to open a web page in Google chrome incognito from android app

查看:111
本文介绍了如何从Android应用程序中打开Goog​​le chrome隐身模式下的网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要在隐身模式下启动Chrome浏览器。



我的代码:

  private void launchBrowser(){
String url =http ://foyr.com;
意图launchGoogleChrome = new Intent(Intent.ACTION_VIEW,Uri.parse(url));
launchGoogleChrome.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
launchGoogleChrome.setPackage(com.android.chrome);
尝试{
startActivity(launchGoogleChrome);
} catch(ActivityNotFoundException e){
launchGoogleChrome.setPackage(null);
startActivity(launchGoogleChrome);


$ / code $ / pre

我发现了几篇文章,但我无法找到解决方案。
此处



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

  private void launchBrowser(){
String url =http://foyr.com;
意图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);
尝试{
startActivity(launchGoogleChrome);
} catch(ActivityNotFoundException e){
launchGoogleChrome.setPackage(null);
startActivity(launchGoogleChrome);
}
}

但Chrome浏览器没有收到来自应用程序的任何意图信息。任何人都可以帮助我在哪里做错了什么?

解决方案

源代码:

  //打开新的隐身标签目前仅限于Chrome或第一方。 
if(!isInternal
&& IntentUtils.safeGetBooleanExtra(
intent,EXTRA_OPEN_NEW_INCOGNITO_TAB,false)){
return true;
}

看起来额外的东西除了分叉Chrome或明确允许由谷歌。


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?

解决方案

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.

这篇关于如何从Android应用程序中打开Goog​​le chrome隐身模式下的网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆