I have a problem downloading an image from Google Cloud Storage public url from my android app. My code works perfectly for images from other sources. The images from Google Cloud Storage can also be accessed from a web browser without problems. Take this image for example: http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg
Here is an intentservice which demonstrates the problem:
public class TestService1 extends IntentService {
public TestService1(){
super("TestService1");
}
@Override
protected void onHandleIntent(Intent intent) {
String urlString="http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(urlString);
HttpResponse response = httpclient.execute(httpget);
}
catch(IOException e){
e.printStackTrace();
}
}
}
This gives me the following error message:
java.lang.IllegalArgumentException: Host name may not be null
I have also tried using httpurlconnection:
public class TestService2 extends IntentService {
public TestService2() {
super("TestService2");
}
@Override
protected void onHandleIntent(Intent intent) {
String urlString="http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg";
try {
URL url = new URL(urlString);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
}
catch(IOException e){
e.printStackTrace();
}
}
}
The error here (which is caught in the catch-block) is
java.net.UnknownHostException: http://tin_images.storage.googleapis.com/1420678062-zmj1qJQe126843HbyJvbUI.jpg
In both of these cases it works fine if I use another url. I prefer using HttpClient as I use that library in the rest of the app.
Is there any way to solve this problem?