How do I pass along HTTP Basic Authentication information to Intent.ACTION_VIEW
? Here's where I'm firing the intent:
public class OutageListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor> {
// ...
@Override
public void onListItemClick(ListView listView, View view, int position, long id) {
super.onListItemClick(listView, view, position, id);
// Get a URI for the selected item, then start an Activity that displays the URI. Any
// Activity that filters for ACTION_VIEW and a URI can accept this. In most cases, this will
// be a browser.
String outageUrlString = "http://demo:[email protected]/opennms/outage/detail.htm?id=204042";
Log.i(TAG, "Opening URL: " + outageUrlString);
// Get a Uri object for the URL string
Uri outageURI = Uri.parse(outageUrlString);
Intent i = new Intent(Intent.ACTION_VIEW, outageURI);
startActivity(i)
}
}
I have also tried Uri.fromParts()
, same deal. Curl works just fine.
Turns out you can add HTTP headers to the Intent via a Bundle, and specifically add an Authorization header with a Base64 encoded user id.
Intent i = new Intent(Intent.ACTION_VIEW, outageURI);
String authorization = user + ":" + password;
String authorizationBase64 = Base64.encodeToString(authorization.getBytes(), 0);
Bundle bundle = new Bundle();
bundle.putString("Authorization", "Basic " + authorizationBase64);
i.putExtra(Browser.EXTRA_HEADERS, bundle);
Log.d(TAG, "intent:" + i.toString());
startActivity(i);
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