How to set user agent for new ACTION_VIEW intent

2019-09-03 19:50发布

问题:

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.