简体   繁体   中英

how to change image file name in android studio?

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);
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM