2

I have an app that starts an activity to stream audio from an HTTP server. Android will ask the user how to complete the activity by listing a bunch of apps that can play streaming audio. Google Play Music is one of them so pretty much every device can do this. This works fine however I've run into a problem with a server that requires authentication done by HTTP headers. The authentication is nothing fancy, just BASIC which is just the username:password base64ed and stuffed in an HTTP header. The problem is, how can I add that to the intent? My existing code is similar to this:

Uri uri = Uri.parse("http://host:5151/download?path=\"blah\"");
Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(uri, "audio/*");

a.startActivity(i); // variable 'a' is defined as an Activity elsewhere and refers to the currently running Activity. Nothing strange there.

The above works when authentication is not required. When it is required, I can do the following when using my existing server:

Uri uri = Uri.parse("http://username:pw@host:5151/download?path=\"blah\"");

Note the username and password inserted before the host. That works for the server I've been currently using as it seems to support an old standard way of passing BASIC authentication in the URL itself. This however is not ideal. The other server I've tried this with fails as it expects the authentication details in an HTTP header, specifically the Authorization header. However, for the header to be inserted into the request the intent would probably require some "extras" to specify the username and password. I have no idea if that's possible and if so, how I'd find out what those extras are.

My question is: is this possible and if so how?

4

0 回答 0