android - Browser.EXTRA_APPLICATION_ID 在 ICS 中不起作用

标签 android browser android-intent

如何在从我的服务启动时重用 Browser.apk 的选项卡?下面是我的代码,但它不适用于 ICS(平板电脑)。

//ICS --> 即使设置了 EXTRA_APPLICATION_ID,浏览器也不会重用该选项卡。

public class MyService extends IntentService {
    ....
    mBrowserIntent = new Intent(Intent.ACTION_VIEW);
    mBrowserIntent.setFlags(Intent.FLAG_FROM_BACKGROUND | 
        Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    mBrowserIntent.putExtra(Browser.EXTRA_APPLICATION_ID , this.getPackageName());
    mBrowserIntent.setData(page.getAddress());
    startActivity(mBrowserIntent);

}

//HC --> 即使没有设置 EXTRA_APPLICATION_ID,它也会重用该选项卡。

public class MyService extends IntentService {
    ....
    mBrowserIntent = new Intent(Intent.ACTION_VIEW);
    mBrowserIntent.setFlags(Intent.FLAG_FROM_BACKGROUND | 
        Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    mBrowserIntent.setData(page.getAddress());
    startActivity(mBrowserIntent);

}

//相关内容:

9221725

最佳答案

感谢@aimango 的回答。这是修复。适用于平板电脑(ICS 和 HC)。

    mBrowserIntent = new Intent(Intent.ACTION_VIEW);
    mBrowserIntent.setPackage("com.android.browser");
    mBrowserIntent.setFlags(Intent.FLAG_FROM_BACKGROUND | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
    mBrowserIntent.putExtra(Browser.EXTRA_APPLICATION_ID , "com.android.browser");
    mBrowserIntent.setData(page.getAddress());
    startActivity(mBrowserIntent);

关于android - Browser.EXTRA_APPLICATION_ID 在 ICS 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9901820/

相关文章:

android - 启动Android Studio时出现的一长串错误

android - AndroidManifest.xml 中是否可以使用相对包名称?

java - 无法解析 JSON 响应对象

javascript - FireFox 上的浏览​​器类型错误 “fsGetSearchListener is not a function”

android - 无法从 Intent 中获取额外的值

android - 致命异常 : java. lang.RuntimeException:系统故障

java - 我的 Android 复利计算器一直崩溃

html - 阻止文本选择超出 div?

java桌面浏览器弹出窗口

Android: Intent.EXTRA_ALLOW_MULTIPLE 只允许单次采摘