Trying to set ImageView from Url with Bitmap - android

I am trying to set my ImageView.I have the url of the image and trying to make it bitmap and after set this bitmap to my ImageView.However, Bitmap result, argument of onPostExecute, is coming as null from download_Image function. It means ' BitmapFactory.decodeStream(is); ' is returning null.
this.ImageView1 = (ImageView) infoWindow.findViewById(R.id.ImageView1);
ImageView1.setTag(URL);
new AsyncTask<ImageView, Void, Bitmap>(){
ImageView imageView = null;
#Override
protected Bitmap doInBackground(ImageView... imageViews) {
final Bitmap[] b = new Bitmap[1];
this.imageView = imageViews[0];
activity.runOnUiThread(new Runnable() {
#Override
public void run() {
b[0] =download_Image((String) imageView.getTag());
}
});
return b[0];
}
#Override
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
public Bitmap download_Image(String url) {
//---------------------------------------------------
URL newurl = null;
try {
newurl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap mIcon_val = null;
try {
URLConnection urlConnection=newurl.openConnection();
InputStream is=urlConnection.getInputStream();
mIcon_val=BitmapFactory.decodeStream(is);
} catch (Exception e) {
e.printStackTrace();
}
return mIcon_val;
//---------------------------------------------------
}
}.execute(ImageView1);
How can I deal with that problem?

Use this code and comment if any problem`public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private String imageUrl ="image url";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView)findViewById(R.id.imageview);
new AsyncTask<ImageView, Void, Bitmap>(){
ImageView imageView = null;
#Override
protected Bitmap doInBackground(ImageView... imageViews) {
final Bitmap[] b = new Bitmap[1];
this.imageView = imageViews[0];
b[0] =download_Image(imageUrl);
return b[0];
}
#Override
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
public Bitmap download_Image(String url) {
//---------------------------------------------------
URL newurl = null;
try {
newurl = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
Bitmap mIcon_val = null;
try {
URLConnection urlConnection=newurl.openConnection();
InputStream is=urlConnection.getInputStream();
mIcon_val= BitmapFactory.decodeStream(is);
} catch (Exception e) {
e.printStackTrace();
}
return mIcon_val;
//---------------------------------------------------
}
}.execute(imageView);}}`

Write this in your gradle dependencies
dependencies {
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.android.support:support-v4:19.1.0'
}
In your activtiy
Glide.with(activity.this).load(your image url).into(imageView);

Related

how to get the return value from my doInBackground task?

I'm new on android studio and I'm trying to do an AsyncTask for my Network operation.
The problem is to get the return variable from it to be able to set the image in the imageview. imgDisplay.setImageBitmap(var)
public class ZoomActivity extends Activity {
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zoom);
Intent intent = getIntent();
String url2 = intent.getStringExtra("image");
ImageView imgDisplay;
Button btnClose;
imgDisplay = (ImageView) findViewById(R.id.imgDisplay);
btnClose = (Button) findViewById(R.id.btnClose);
//Bitmap var = return of doInBackground??????????
imgDisplay.setImageBitmap(var);
btnClose.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ZoomActivity.this.finish();
}
});
}
private class MyTask extends AsyncTask<String, Integer, String> {
#Override
protected String doInBackground(String... Params) {
String myString = Params[0];
try {
URL url = new URL(URL???); //how to pass url2 var here?
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;
}
}
}
}
any examples?
First, declare this asynctask class:
class MyTask extends AsyncTask<String,Void,Bitmap>{
#Override
protected Bitmap doInBackground(String... strings) {
String myString = Params[0];
try {
URL url = new URL(myString);
Bitmap myBitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
return myBitmap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
return null;
}
#Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
imgDisplay.setImageBitmap(bitmap);
}
}
Your zoomActivity changes to:
public class ZoomActivity extends Activity {
ImageView imgDisplay;
#SuppressLint("NewApi")
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zoom);
Intent intent = getIntent();
String url2 = intent.getStringExtra("image");
Button btnClose;
imgDisplay = (ImageView) findViewById(R.id.imgDisplay);
btnClose = (Button) findViewById(R.id.btnClose);
//call asynctask
new MyTask().execute(url2);
btnClose.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ZoomActivity.this.finish();
}
});
}
hope this works
When your doInBackground returns an object, it goes to the method onPostExecute as an input parameter, and that method executes in the UI thread and not a parallel thread, so you can set the imag
AsyncTask
This this for reference.
Change you MyTask to
private class MyTask extends AsyncTask<String, Integer, BitMap> {
#Override
protected Bitmap doInBackground(String... Params) {
String myString = Params[0];
try {
URL url = new URL(URL???); //how to pass url2 var here?
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;
}
}
protected void onPostExecute(Bitmap result) {
//set the Image here.
imgDisplay.setImageBitmap(result);
}
}
You should let the AsyncTask return a Bitmap instead of a String
private class MyTask extends AsyncTask<String, Integer, Bitmap> {
#Override
protected Bitmap doInBackground(String... Params) {
String myString = Params[0];
try {
URL url = new URL(myString); //how to pass url2 var here?
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;
}
}
protected void onPostExecute(Bitmap result) {
//set your bitmap here to your imgDisplay
}
}
Then you start the task with
new MyTask().execute(/* urlString*/)

download BLOB in AsyncTask

I have a method where I would download an image from a folder based on the link passed into the AsyncMethod
I have since made some changes and now the image resides on the database. I am having a little problem editing my downloadAsyn Task as it no longer receives a link but instead a long string of characters (BLOB from the database).
I have pasted my code below, and is trying to find assistance in assigning cImg1 the bitmap to display my image.
Thank you
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];// this parameter once had url of image
//but now it has the image bitmap.
Bitmap cImg1= null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
// cImg1= BitmapFactory.decodeStream(in);
cImg1=urldisplay;//Assign strings to BitMap?
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return cImg1;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
Below code will be worked fine.
public class DownloadImageTask extends AsyncTask<String, Integer, Bitmap> {
Context _context;
ImageView _imageView;
private OnResponseListener _responder;
private String _errorMessage;
public DownloadImageTask(ImageView bmImage, OnResponseListener responseListener) {
this._imageView = bmImage;
_context = bmImage.getContext();
_responder = responseListener;
}
#Override
protected void onPreExecute() {
super.onPreExecute();
}
protected Bitmap doInBackground(String... urls) {
int count;
String urlDisplay = urls[0];
Bitmap bitmap = null;
try {
InputStream in = new java.net.URL(urlDisplay).openStream();
BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true; options.inInputShareable = true;
bitmap = BitmapFactory.decodeStream(in, null, options);
URLConnection urlConnection = new java.net.URL(urlDisplay).openConnection();
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
int lengthOfFile = urlConnection.getContentLength();
byte data[] = new byte[1024];
long total = 0;
while ((count = inputStream.read(data)) != -1) {
total += count;
int progress = (int) total * 100 / lengthOfFile;
publishProgress(progress);
}
} catch (Exception e) {
_errorMessage = e.getMessage();
e.printStackTrace();
}
return bitmap;
}
#Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
}
protected void onPostExecute(Bitmap result) {
if (result != null){
_responder.onSuccess(result);
}
else
_responder.onFailure(_errorMessage);
}
public interface OnResponseListener {
void onSuccess(Bitmap result);
void onFailure(String message);
}
}

Image does not loaded and throwingjava.net.MalformedURLException

i am parsing a json string from which i get the url of image. then i pass that url to a method to get the image and display it in an imageview but the image does not loaded and throws an exception of java.net.MalformedURLException. when i try to pass the image url directly to the method then it gets loaded. so i dont know where is the error. Any help will be appreciated. thanks in advance. my code is below
public class CompanyDetailActivity extends Activity {
ImageView coverimage;
ImageView profileimage;
TextView fullname;
TextView tagline;
TextView industry;
TextView teamsize;
TextView about;
TextView year;
TextView location;
String Coverimage;
String Profimage;
String Fullname;
String Tagline;
String Industry;
String Teamsize;
String About;
String Year;
String Location;
// Bitmap bitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.companydetails);
coverimage = (ImageView) findViewById(R.id.CoverImage);
profileimage = (ImageView) findViewById(R.id.ProfileImage);
fullname = (TextView) findViewById(R.id.FullName);
tagline = (TextView) findViewById(R.id.TagLine);
industry = (TextView) findViewById(R.id.IndustryName);
teamsize = (TextView) findViewById(R.id.TeamSize);
about = (TextView) findViewById(R.id.CompanyAbout);
year = (TextView) findViewById(R.id.FoundYear);
location = (TextView) findViewById(R.id.Location);
new DetailsAsynTask()
.execute("http://www.mygmn.com/joblink/wp-admin/admin-ajax.php?action=joblink_searchcompanies&company_id=1180");
GetXMLTask task = new GetXMLTask();
task.execute(Coverimage);
}
public class DetailsAsynTask extends AsyncTask<String, Void, Boolean> {
#Override
protected Boolean doInBackground(String... arg0) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(arg0[0]);
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
// to get response
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jObj = new JSONObject(data);
JSONObject MainObject = jObj.getJSONObject("data");
CompanyDetailsModel company = new CompanyDetailsModel();
Coverimage = company.setCoverImage(MainObject
.getString("cove_img"));
Profimage = company.setCompanyProfPicture(MainObject
.getString("company_profile_picture"));
Fullname = company.setCompanyFullName(MainObject
.getString("company_full_name"));
Tagline = company.setComapnyTagLine(MainObject
.getString("company_tagline"));
Industry = company.setCompanyInustry(MainObject
.getString("company_industry"));
Teamsize = company.setCompanyTeamSize(MainObject
.getString("company_teamsize"));
About = company.setCompanyAbout(MainObject
.getString("company_about"));
Year = company.setCompanyFoundYear(MainObject
.getString("company_foundyear"));
Location = company.setCompanyLocation(MainObject
.getString("company location"));
return true;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
#Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if (result == false) {
} else {
fullname.setText(Fullname);
tagline.setText(Tagline);
industry.setText(Industry);
teamsize.setText(Teamsize);
about.setText(About);
year.setText(Year);
location.setText(Location);
}
}
}
private class GetXMLTask extends AsyncTask<String, Void, Bitmap> {
#Override
protected Bitmap doInBackground(String... urls) {
Bitmap map = null;
for (String url : urls) {
map = downloadImage(url);
}
return map;
}
// Sets the Bitmap returned by doInBackground
#Override
protected void onPostExecute(Bitmap result) {
coverimage.setImageBitmap(result);
}
// Creates Bitmap from InputStream and returns it
private Bitmap downloadImage(String url) {
Bitmap bitmap = null;
InputStream stream = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
try {
stream = getHttpConnection(url);
bitmap = BitmapFactory.decodeStream(stream, null, bmOptions);
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
// Makes HttpURLConnection and returns InputStream
private InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
}
}
java.net.MalformedURLException can come due to security reason .you have to add http:// or https:// with your url images.
You are running two asynctasks inside onCreate() method .As these are asynchronous your GetXMLTask was executed with String CoverImage as null .
So , moving this code :
GetXMLTask task = new GetXMLTask();
task.execute(Coverimage);
to the onPostExecute() Method of your Details asynctask will solve the problem .
ok, use this code
public class ImageLoading {
public enum BitmapManager {
INSTANCE;
private final Map<String, SoftReference<Bitmap>> cache;
private final ExecutorService pool;
private Map<ImageView, String> imageViews = Collections
.synchronizedMap(new WeakHashMap<ImageView, String>());
private Bitmap placeholder;
BitmapManager() {
cache = new HashMap<String, SoftReference<Bitmap>>();
pool = Executors.newFixedThreadPool(5);
}
public void setPlaceholder(Bitmap bmp) {
placeholder = bmp;
}
public Bitmap getBitmapFromCache(String url) {
if (cache.containsKey(url)) {
return cache.get(url).get();
}
return null;
}
public void queueJob(final String url, final ImageView imageView,
final int width, final int height) {
/* Create handler in UI thread. */
final Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
String tag = imageViews.get(imageView);
if (tag != null && tag.equals(url)) {
if (msg.obj != null) {
imageView.setImageBitmap((Bitmap) msg.obj);
} else {
imageView.setImageBitmap(placeholder);
Log.d(null, "fail " + url);
}
}
}
};
pool.submit(new Runnable() {
#Override
public void run() {
final Bitmap bmp = downloadBitmap(url, width, height);
Message message = Message.obtain();
message.obj = bmp;
Log.d(null, "Item downloaded: " + url);
handler.sendMessage(message);
}
});
}
public void loadBitmap(final String url, final ImageView imageView,
final int width, final int height) {
imageViews.put(imageView, url);
Bitmap bitmap = getBitmapFromCache(url);
// check in UI thread, so no concurrency issues
if (bitmap != null) {
Log.d(null, "Item loaded from cache: " + url);
imageView.setImageBitmap(bitmap);
} else {
imageView.setImageBitmap(placeholder);
queueJob(url, imageView, width, height);
}
}
private Bitmap downloadBitmap(String url, int width, int height) {
try {
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) new URL(
url).getContent());
bitmap = Bitmap.createScaledBitmap(bitmap, width, height, true);
cache.put(url, new SoftReference<Bitmap>(bitmap));
return bitmap;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
Directly use this code,and where you are using downloading code ,use this code
ImageLoading.BitmapManager.INSTANCE.loadBitmap("http://"+image, holder.img, 150, 180);
Your URL is okay from your server response. Instead of loading the image manually try Picasso Library
with this library, you will just need to do-
Picasso.with(context).load("http://i.imgur.com/DvpvklR.png").into(imageView);

App force closing when Async tries to get Bitmap from url

I have an Async running to get data from a page I've created. It get's the text just fine, but when I try and get the image from the image src via another class the app force closes. Here is the code that it force closes on:
public class FullReportActivity extends NavigationActivity {
private TextView textView;
private String url = "http://www.backcountryskiers.com/sac/sac-full.html";
private ImageView ivDangerRose;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
// tell which region this covers
getSupportActionBar().setSubtitle("...from Sierra Avalanche Center");
setContentView(R.layout.activity_fullreport);
textView = (TextView) findViewById(R.id.todaysReport);
ivDangerRose = (ImageView) findViewById(R.id.dangerRose);
fetcher task = new fetcher();
task.execute();
}
// GET THE IMAGE and RETURN IT
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;
}
}
class fetcher extends AsyncTask<String, Void, String> {
private ProgressDialog dialog = new ProgressDialog(
FullReportActivity.this);
private Document doc = null;
private Document parse = null;
private String results = null;
private String reportDate = null;
private Bitmap bimage = null;
#Override
protected String doInBackground(String... params) {
try {
doc = Jsoup.connect(url).get();
Log.e("Jsoup", "...is working...");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("Exception", e.getMessage());
}
parse = Jsoup.parse(doc.html());
results = doc.select("#fullReport").outerHtml();
Element dangerRoseImg = doc.getElementById("reportRose")
.select("img").first();
String dangerRoseSrc = dangerRoseImg.absUrl("src");
Log.i("Report Rose IMG", dangerRoseSrc);
bimage = getBitmapFromURL(dangerRoseSrc);
ivDangerRose.setImageBitmap(bimage);
return results;
}
#Override
protected void onPostExecute(String result) {
dialog.dismiss();
// smooth out the long scrolling...
textView.setMovementMethod(ScrollingMovementMethod.getInstance());
reportDate = parse.select("#reportDate").outerHtml();
textView.setText(Html.fromHtml(reportDate + results));
textView.setPadding(30, 20, 20, 10);
}
#Override
protected void onPreExecute() {
dialog.setMessage("Loading Full Report from the Sierra Avalanche Center...");
dialog.show();
}
}
}
I have run this Async alone to get the image like so without a force close and I don't understand what i am doing different besides calling the method:
public class MainActivity extends Activity {
public String durl = "http://www.sierraavalanchecenter.org/dangerrose.png?a=2955";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new DownloadImageTask((ImageView) findViewById(R.id.dangerrose))
.execute(durl);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap drose = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
drose = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return drose;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
}
}
}
This class gets the image src and creates a bitmap and puts it into an ImageView, what is different here than on my first class???
Frustrated.
You can not modify UI from background thread.
move ivDangerRose.setImageBitmap(bimage); in onPostExecute
In the method doInBackground
remove --> ivDangerRose.setImageBitmap(bimage);
as you can't modify UI in background process.
If you still want you can try runOnUiThread Method
In doInBackground() we should not access the content of activity.

How do i return a bitmap from an Asyncronous task

im fetching an image from internet using the below code using an Async task,But the bitmp returns from the function is always null.
private Bitmap asyncTaskFetchImage(final String imgeurl) {
// TODO Auto-generated method stub
new AsyncTask<Object, Object, Object>() {
#Override
protected void onPreExecute() {
progress_Dialog = ProgressDialog.show(this, "", "Loading");
}
#Override
protected Object doInBackground(Object... params) {
// TODO Auto-generated method stub
try
{
toSendBg=LoadImageFromURL(imgeurl);
System.gc();
return 0;
}
catch (Exception e) {
e.printStackTrace();
}
return 0;
}
#Override
protected void onPostExecute(Object result) {
if (progress_Dialog != null) {
progress_Dialog.dismiss();
}
}
}.execute();
return toSendBg;
}
Is this the exact way to return value from an Asyntask?
Try below code to download image from web using AsyncTask and display in imageview.
public class MainActivity extends Activity {
ImageView mImgView1;
static Bitmap bm;
ProgressDialog pd;
String imageUrl = "https://www.morroccomethod.com/components/com_virtuemart/shop_image/category/resized/Trial_Sizes_4e4ac3b0d3491_175x175.jpg";
BitmapFactory.Options bmOptions;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImgView1 = (ImageView) findViewById(R.id.mImgView1);
pd = ProgressDialog.show(MainActivity.this, "Aguarde...",
"Carregando...");
new ImageDownload().execute("");
}
public class ImageDownload extends AsyncTask<String, Void, String> {
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
loadBitmap(imageUrl, bmOptions);
return imageUrl;
}
protected void onPostExecute(String imageUrl) {
pd.dismiss();
if (!imageUrl.equals("")) {
mImgView1.setImageBitmap(bm);
} else {
Toast.makeText(MainActivity.this,
"Não foi possível obter resultados", Toast.LENGTH_LONG)
.show();
}
}
}
public static Bitmap loadBitmap(String URL, BitmapFactory.Options options) {
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bm = BitmapFactory.decodeStream(in, null, options);
in.close();
} catch (IOException e1) {
}
return bm;
}
private static InputStream OpenHttpConnection(String strURL)
throws IOException {
InputStream inputStream = null;
URL url = new URL(strURL);
URLConnection conn = url.openConnection();
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
} catch (Exception ex) {
}
return inputStream;
}
}
private Bitmap asyncTaskFetchImage(final String imgeurl) {
Bitmap bmp=null;
new AsyncTask<Object, Object, Object>() {
...
and in your doInBackground method change return to
return toSendBg;
and
#Override
protected void onPostExecute(Object result) {
if (progress_Dialog != null) {
progress_Dialog.dismiss();
bmp=(Bitmap)result;
}
}
}.execute();
return bmp;
Try this..,.

Categories

Resources