I have a specific requirement where I have to fire a url on the browser from my activity. I am able to do this with the following code :
Intent browserIntent = new Intent(
Intent.ACTION_VIEW, Uri.parse(
pref.getString("webseal_sso_endpoint", "") + "?authorization_code="
+ code + "&webseal-ip=" + websealIP
)
);
activity.startActivity(browserIntent);
activity.finish();
Now, I want to invoke this webseal_sso_endpoint by passing an extra header. say ("user":"username") How can I implement this? Thanks a lot in advance!
Fill out the Create a header fields as follows: In the Name field, enter the name of your header rule (for example, My header ). From the Type menu, select Request, and from the Action menu, select Set. In the Destination field, enter the name of the header affected by the selected action.
A common way to achieve this is with the next code:String url = "http://www.stackoverflow.com"; Intent i = new Intent(Intent. ACTION_VIEW); i. setData(Uri. parse(url)); startActivity(i);
I featured out how to add a header. Here is my code:
Intent browserIntent = new Intent(
Intent.ACTION_VIEW, Uri.parse(url));
Bundle bundle = new Bundle();
bundle.putString("iv-user", username);
browserIntent.putExtra(Browser.EXTRA_HEADERS, bundle);
activity.startActivity(browserIntent);
activity.finish();
Recommended method to do this would be to use the Uri class to create your URI. Helps ensure that everything is defined correctly and associates the correct key to value for your URI.
For example, you want to send a Web intent with this URL:
http://webseal_sso_endpoint?authorization_code=SomeCode&webseal-ip=WEBSEALIP
And you have a defined URL and parameters you want to send, you should declare these as static final fields, like so:
private final static String BASE_URL = "http://webseal_sso_endpoint";
private final static String AUTH_CODE = "authorization_code";
private final static String IP = "webseal-ip";
private final static String USERNAME = "user";
You can then use these, like so:
Uri builtUri = Uri.parse(BASE_URL).buildUpon()
.appendQueryParameter(AUTH_CODE, code)
.appendQueryParameter(IP, websealIP)
.build();
Now if you want to add another parameter, add another appendQueryParameter, like so:
Uri builtUri = Uri.parse(BASE_URL).buildUpon()
.appendQueryParameter(AUTH_CODE, code)
.appendQueryParameter(IP, websealIP)
.appendQueryParameter(USERNAME, user)
.build();
You can convert to a URL if needed using:
URL url = new URL(builtUri.toString());
Should come out like this:
http://webseal_sso_endpoint?authorization_code=SomeCode&webseal-ip=WEBSEALIP&user=SomeUsersName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With