Exception E/AsyncHttpRH: User-space exception detected - android

I am trying to download images from server to be used as map markers icon in my android app.
This is how I am trying to download the images:
public Bitmap getBitmapFromURL(String imageUrl) {
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
And this is how I am calling this method:
String urlbitmap = "https://faro.red/buju/administrar/application/admin/usuarios/" + foto;
Log.d("RES SUVJETC","numProfesionales urlbitmap:"+urlbitmap);
Bitmap postbitmap = getBitmapFromURL(urlbitmap);
For the variable urlbitmap, this is the log output:
https://faro.red/buju/administrar/application/admin/usuarios/blue-user-icon.png
The image is at this URL.
I am getting an exception at line:
InputStream input = connection.getInputStream();
The exception output is this:
19-07-26 14:25:41.984 20497-20497/com.mpidesarrollo.buju E/AsyncHttpRH: User-space exception detected!
android.os.NetworkOnMainThreadException
at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1303)
at com.android.org.conscrypt.Platform.blockGuardOnNetwork(Platform.java:300)
at com.android.org.conscrypt.OpenSSLSocketImpl$SSLOutputStream.write(OpenSSLSocketImpl.java:839)
at com.android.okhttp.okio.Okio$1.write(Okio.java:81)
at com.android.okhttp.okio.AsyncTimeout$1.write(AsyncTimeout.java:155)
at com.android.okhttp.okio.RealBufferedSink.flush(RealBufferedSink.java:221)
at com.android.okhttp.internal.http.HttpConnection.flush(HttpConnection.java:141)
at com.android.okhttp.internal.http.HttpTransport.finishRequest(HttpTransport.java:60)
at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:1154)
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:976)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:509)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:438)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:247)
at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getInputStream(DelegatingHttpsURLConnection.java:210)
at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java)
at com.mpidesarrollo.buju.HomeFragment.getBitmapFromURL(HomeFragment.java:355)

I have the same problem. It solved by changing the url protocol from https to http

Related

Android Notification Image Sometimes not displaying

I have coded to fetch the image from amazonaws and show it in the expanded view of notification.below is the code
try {
URL url = new URL(imageUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return BitmapFactory.decodeStream(input);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
The same code works and showing the image in some devices and not in others at the same time.
Images which are not displaying getting exceptions like as below
java.net.UnknownHostException: Unable to resolve host
"examples3.s3.amazonaws.com": No address associated with hostname
java.net.ConnectException: Failed to connect to
examples3.s3.amazonaws.com/1.2.3.4:5(some ip showing, this is for the only
reference)

How to get XML data from https url in Android

I want to get XML data from the web server https://ruralfire.qld.gov.au/bushfirealert/bushfireAlert.xml
However, I can't do it because my codes always have an error "javax.net.ssl.SSLHandshakeException: Connection closed by peer".
And my InputStream is always null, so I can't do anything with it (such as parsing).
I ensure that the problem is in my connection but I don't know how to solve it.
This is my code in connecting to the web server:
private InputStream downloadUrl(String urlString) throws IOException {
URL url;
url = new URL(urlString);
InputStream is = null;
try {
HttpsURLConnection con = (HttpsURLConnection)url.openConnection();
con.setDoInput(true);
is = con.getInputStream();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return is;
}
May you help me to solve this problem ?
Thank you so much.

cookies with getBitmapFromURL()

I am passing the url to get the images from the server e.g.
getBitmapFromURL("http://abc.xyz.in/logo.jpg");
But it is not returning anything. Saying that images are private. So my question is that is there anyway to pass the cookie to getBitmapFromURL() method. So that i can get the images. Or any other alternative is there? Thanks a lot.
2014, if the answer is feasible to you please raise the answer and points
This should do the trick:
public static Bitmap getBitmapFromURL(String src) {
try {
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Don't forget to add the internet permission and any other permission which is needed in your manifest.
I got my answer. I can do this by using following line:
connection.addRequestProperty("key", value);

Making Sprite from image from web/server in AndEngine

I want to make a Sprite from an image which is placed on my server I have complete path of the image. Is it possible to do it in AndEngine.? Currently I am working in GLES 2.
first you need generate a link to your image and after,watch this code for load the image in a TextureRegion using HttpURLConnection and InputStream:
try {
ITexture mTexture = new BitmapTexture(pEngine.getTextureManager(), new IInputStreamOpener() {
#Override
public InputStream open() throws IOException {
URL url = new URL("https://yourImage.png");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(input);
return in;
}
});
mTexture.load();
TextureRegion MyImageFromWeb = TextureRegionFactory.extractFromTexture(mTexture);
} catch (IOException e) {
Debug.e(e);
}
it is possible you just have to download it first with HttpGet or UrlConnection in Background Thread
But i would recommend you to download all your assets in some kind of splash screen and saving them into sdcard

Getting MalformedURLException: Protocol not found?

I am getting MalformedURLException: Protocol not found, when I am trying to load image from URL sting. That image is displaying in Browser when I paste that URL. But not displaying in ImageView. I've used this code:
public static Bitmap getBitmapFromURL(String src) {
try
{
URL url = new URL(src);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
return myBitmap;
}
catch (IOException e) {
e.printStackTrace();
return null;
}
}
Please anybody tell me whats the problem? It will be very helpful to me.
Its a
http://74.208.68.90/webservice/images/image44.png
Your code is OK.
malformedexception comes when there is some problem in your url
try to encode your parameters in url with url encoder and protocall not found shows
http is missing from your url
String url = url +"/" + UrlEncoder.encode(param);
I think it is "src" that may have problem,

Categories

Resources