Hi there,

I'm writing an podcast playing application.  The application has pre-
defined feeds but I want to cache the image of the feed for 30 days.
However, on the initial creation of the podcast I am downloading the
image, and trying to save it to the SD card using the code below:

public long createPodcast(RssFeed feed, String feedUrl) {
        ContentValues insertValues = new ContentValues();
        insertValues.put(KEY_FEED_TITLE, feed.title);
        insertValues.put(KEY_FEED_FEED_URL, feedUrl);
        insertValues.put(KEY_FEED_LINK, feed.link);
        insertValues.put(KEY_FEED_DESCRIPTION, feed.description);
        insertValues.put(KEY_FEED_PUBDATE, feed.pubDate);
        insertValues.put(KEY_FEED_IMAGE_URL, feed.imageUrl);
        insertValues.put(KEY_FEED_IMAGE_WIDTH, feed.imageWidth);
        insertValues.put(KEY_FEED_IMAGE_HEIGHT, feed.imageHeight);
        insertValues.put(KEY_FEED_SUBSCRIBED, false);

        long rowId = mDb.insert(TABLE_PODCAST_LIST, null,
insertValues);

        String storage_state = Environment.getExternalStorageState
();
        if (storage_state.contains("mounted")) {
                File f = Environment.getExternalStorageDirectory();
                File j = new File(f, "twitcast");
                try {
                                URL users_avatar = new URL(feed.imageUrl);
                                HttpURLConnection conn = (HttpURLConnection)
users_avatar.openConnection();
                                conn.setDoInput(true);
                                conn.connect();
                                InputStream is = conn.getInputStream();
                                Bitmap bmImg = BitmapFactory.decodeStream(is);

                                File k = new File(j, rowId + ".jpg");
                                k.mkdirs();
                                k.createNewFile();
                                FileOutputStream fos = new FileOutputStream(k);
                                bmImg.compress(Bitmap.CompressFormat.JPEG, 100, 
fos);
                        } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                        }
        }
        return rowId;
    }

However, it keeps failing on the line k.createNewFile(); with the
error:
WARN/System.err(10727): java.io.IOException: Parent of file is not a
directory: /sdcard/twitcast/1.jpg

I've checked and I have write permission and the SD card is mounted,
and I have android.permission.MOUNT_UNMOUNT_FILESYSTEMS included in my
manifest.

Does anyone have any ideas why this keeps failing?

Thanks,
Tane Piper

--~--~---------~--~----~------------~-------~--~----~
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