How to set user agent for new ACTION_VIEW intent

走远了吗. 提交于 2019-12-24 19:05:42

问题


In my application I am launching a new Intent with url (browser) using the following code:

Intent myIntent = new Intent(Intent.ACTION_VIEW,Uri.parse(url));                
try {
    context.startActivity(myIntent);
} catch (ActivityNotFoundException e) {
    Log.e(TAG, "cannot initiate Browser", e);
}

Is there a way tolet the new activity to send user agent

thanks -Z


回答1:


  1. One can not programmatically set (from within an app) user's browser to display a custom user-agent string. However, users can do this by hand via some fiddling, but then this is set system wide.

  2. If you need to send custom user-agent, you can embedded browser into your app via WebView. Then you can set custom user-agent.




回答2:


myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

might help you.



来源:https://stackoverflow.com/questions/4802869/how-to-set-user-agent-for-new-action-view-intent

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