1

I am downloading an image from URL and displaying on an imageview but the problem is if image name starts with a digit it can't be displayed.

private class DownloadFilesTask extends AsyncTask<String, Void, Bitmap> {
    protected Bitmap doInBackground(String... urls) {

        try {

            URL url = new URL(urls[0]);
            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 onProgressUpdate(Integer... progress) {

    }

    protected void onPostExecute(Bitmap result) {
        //loading.dismiss();

        String image_name = result.toString();
        if( Character.isDigit(image_name.charAt(0))){

        }
        imageView.setImageBitmap(result);
        imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
    }
}
zaheer
  • 143
  • 10

1 Answers1

1

Since code provided is unclear, so this might help you. Use Picasso or Universal Image Loader to load Image on ImageView or save bitmap to sdCard and then load it see https://stackoverflow.com/a/34629526/5057663

naqi
  • 55
  • 8