btw, i know this isn't directly connected to the issue at hand, but i'd recommend closing the FileInputStream in a finally block so you don't leak file descriptors.


Here's the code:

public class ProcessFiles extends AsyncTask<Void, String,Void> {

        protected Void doInBackground(Void unused) {

                File sdcard = new File("/sdcard");
                for (int i = 0; i < sdcard.list().length; i++) {
                        File file = new File(sdcard,sdcard.list()[i]);
                        try {
                                FileInputStream is = new FileInputStream(file);
                                String artUrl= artFinder.findArtwork(is, this,
context);
                                publishProgress(artUrl);
                        if (fingerprinter.getError() != null) {
                                        break; // Error occurred so quit
                                }
                        } catch (FileNotFoundException e) {
                                e.printStackTrace();
                        }
                }
                return null;
        }

        public void onProgressUpdate(String artUrl) {
                ArtRetrievalTask task = new ArtRetrievalTask();
                task.execute(artUrl);
        }
    }
}

public class ArtRetrievalTask extends AsyncTask<String ,
Void,Drawable> {

        protected Drawable doInBackground(String artUrl) {
                Drawable art = null;
                if (artUrl != null && artUrl!= null) {
                        try {
                        HttpClient client = new DefaultHttpClient();
                        HttpParams params = client.getParams();

HttpConnectionParams.setConnectionTimeout(params, 15000);

                        HttpGet httpGet = new HttpGet(artUrl);
                        HttpResponse httpResponse = client.execute(httpGet);
                        HttpEntity responseEntity = httpResponse.getEntity();
byte[] artData = EntityUtils.toByteArray(responseEntity);

                                if ( artData != null && artData .length > 0) {
// We could store the cover art onto the hard drive. For this
demo however, we simply load directly into
                                        // a Drawable for display by the UI.
ByteArrayInputStream is = new ByteArrayInputStream(artData ); art = Drawable.createFromStream(is, "src");
                                }
                        } catch (SocketTimeoutException e) {
                                e.printStackTrace();
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
                }
        return coverArt;
        }

        protected void onPostExecute(Drawable   coverArt) {
                imageView.setImageDrawable(coverArt);
        }
    }
}

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


--
jason.vp.engineering.particle

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to