Flick Android Failed to create image decoder with message 'unimplemented'

3k Views Asked by At

I'm making a project for android for my university so it is simple application. I'm trying to download from Flickr service some image and show it in my app but when the app have download URL and JSON script android cant convert that to image. I have that message in run info

Failed to create image decoder with message 'unimplemented'

And here is code with download:

package happyhaker.konrad.zdj_z_netu;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.util.Base64;
import android.util.Log;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class FlickrAPI {
    static final String BASE_URL="https://api.flickr.com/services/rest";
    MainActivity ma;
    public FlickrAPI(MainActivity ma)
    {
        this.ma=ma;

    }
    public void link()
    {
        String url=konstrukcjaURL();
        Log.d("LINK: ",url);
        ZdjeciaAsync task=new ZdjeciaAsync();
        task.execute(url);
    }
    public void link_zdj()
    {
        FotoRequestAsync task = new FotoRequestAsync();
        String fotoURL=konstrukcjaURL();
        task.execute(fotoURL);
    }
    public String konstrukcjaURL(){
        String url=BASE_URL;
        url+="?method=flickr.people.getPublicPhotos";
        url+="&api_key="+ma.API_KEY;
        url+="&user_id=163605973@N02";
        url+="&format=json";
        url+="&nojsoncallback=1";
       // url+="&extras=date_taken,url_h";
        return url;
    }
    public class FotoRequestAsync extends AsyncTask<String, Void, Bitmap>{

        @Override
        protected Bitmap doInBackground(String... strings) {

            Bitmap bitmap = null;
            try {
                URL url = new URL(strings[0]);
                HttpURLConnection urlConnection=(HttpURLConnection) url.openConnection();
                InputStream inputStream = urlConnection.getInputStream();
                Log.e("String do mapy ", inputStream.toString());
                //byte [] dekodowanie = Base64.decode(String.valueOf(inputStream),Base64.DEFAULT);
                bitmap=  BitmapFactory.decodeStream(inputStream);

            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return bitmap;
        }
        @Override
        protected void onPostExecute(Bitmap bitmap)
        {
            super.onPostExecute(bitmap);
            ma.otrzymane_foty(bitmap);
        }
    }
    public class ZdjeciaAsync extends AsyncTask<String, Void, List<FlickrPhoto>>{

        @Override
        protected List<FlickrPhoto> doInBackground(String... strings) {
            String url=strings[0];
            List<FlickrPhoto> fotki=new ArrayList<>();
            try {
                URL urlobjekt=new URL(url);
                HttpURLConnection stronka=(HttpURLConnection)  urlobjekt.openConnection();
                String odp="";
                InputStream inputStream=stronka.getInputStream();
                InputStreamReader czytnik=new InputStreamReader(inputStream);
                int dane=czytnik.read();
                while (dane !=-1)
                {
                    odp+=(char)dane;
                    dane= czytnik.read();
                }
                Log.e("W tle",odp);
                JSONObject jsonObject =new JSONObject(odp);
                JSONObject zdjencie = jsonObject.getJSONObject("photos");
                JSONArray zdjencia=zdjencie.getJSONArray("photo");
                for (int i=0;i<zdjencia.length();i++)
                {
                    JSONObject pojedyncze_zdjecie=zdjencia.getJSONObject(i);
                    FlickrPhoto photka= new FlickrPhoto(pojedyncze_zdjecie);

                    if(photka !=null)
                    {
                            fotki.add(photka);
                    }
                }
            }

            catch (Exception e){
                e.printStackTrace();
            }
            return fotki;
        }

        @Override
        protected void onPostExecute(List<FlickrPhoto> fotosy){
            super.onPostExecute(fotosy);
            Log.e("POST EXECUTE Rozmiar tablicy ze zdjenciami ", String.valueOf(fotosy.size()));
            ma.otrzymane_txt(fotosy);
        }



       /* private FlickrPhoto parseFlickrPhoto(JSONObject fotka)
        {
            FlickrPhoto fota=null;
            try {
                    String id=fotka.getString("id");
                    String title=fotka.getString("title");
                    String url=fotka.getString("url_h");
                    fota=new FlickrPhoto()
            }
            catch (Exception e)
            {

            }
            return fota;
        }*/
    }
}
0

There are 0 best solutions below