如何在从我的服务启动时重用 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);
我是一名优秀的程序员,十分优秀!