Browser.EXTRA_APPLICATION_ID不工作的ICS [英] Browser.EXTRA_APPLICATION_ID not working in ICS
问题描述
如何重用Browser.apk的选项卡时,从我的服务启动了吗?下面是我的code,但它不能在ICS(片)工作。
How to reuse the Tab of the Browser.apk when start it from my service? Below is my code but it does not work in ICS(tablet).
// ICS - >即使EXTRA_APPLICATION_ID设置,浏览器不会重用的标签
// ICS --> Even EXTRA_APPLICATION_ID is set, the browser does NOT reuse the tab.
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未设置重复使用的标签
// HC --> Even EXTRA_APPLICATION_ID is NOT set it reuse the tab.
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);
}
//相关的:
// Related to:
<一个href="http://stackoverflow.com/questions/9221725/how-to-avoid-loading-local-page-in-new-tab-on-default-android-browser">9221725
推荐答案
感谢@aimango的答案。这是该修补程序。工程为平板电脑(包括ICS和HC)。
Thanks for the answer of @aimango. Here is the fix. Works for tablets(both ICS and 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);
这篇关于Browser.EXTRA_APPLICATION_ID不工作的ICS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!