Opening url in the last open tab in chrome

人盡茶涼 提交于 2020-01-25 04:16:06

问题


I am getting an issue while opening URL in my default browser (Chrome)

My requirement is opening URL in the last open tab in Chrome browser for 4.4.4 (Chrome is default browser). NOT in a new tab.

Below code is opening URL in a new tab:

Intent mBrowserIntent = new Intent(Intent.ACTION_VIEW);
mBrowserIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);                                           mBrowserIntent.putExtra(Browser.EXTRA_APPLICATION_ID,mContext.getPackageName());                    mBrowserIntent.addCategory(Intent.CATEGORY_BROWSABLE);
mBrowserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);             
mBrowserIntent.setData(Uri.parse(mUrl));
mContext.startActivity(mBrowserIntent);

Please help in resolving this issue.

Thanks,


回答1:


This works for me, note that you should not use getPackageName():

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://yahoo.com"));
intent.putExtra(Browser.EXTRA_APPLICATION_ID, "com.android.browser");
startActivty(intent);

EDIT: I just tested it on 4.2.2, and it works.



来源:https://stackoverflow.com/questions/26879683/opening-url-in-the-last-open-tab-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!