Figured it out by adding a loop on startup that waits for media to be
mounted:

private File backgroundToJPG() {
                String status = Environment.getExternalStorageState();
                if (status.equals(Environment.MEDIA_MOUNTED)) {
                        File d = new
File(Environment.getExternalStorageDirectory());
                        d.mkdirs();
                        File f = new File(d,"/Custom.jpg");
                        if (!f.exists()){return null;}
                        return f;
                } else {
                        //keep calling back until media is mounted!
                        try{
                           Thread.sleep(1000);
                        }catch(InterruptedException e){ }

                        File tmp = backgroundToJPG();
                        return null;
                }
        }


On Nov 7, 1:20 am, Koops <[email protected]> wrote:
> Hello there I was wondering if someone may be able to help me...
>
> I have a Live Wallpaper app that is working very well on Eclair but
> there is a strange issue with Froyo that I can't find any information
> about.  The user is able to select a custom picture as a background
> from their gallery and it will be saved to internal storage (/
> Snowflakes/CustomBG.jpg) and applied as a background to the live
> wallpaper.  That all works fine until the user reboots their phone...
> The problem is that the internal storage doesn't seem to be mounted in
> time for when the live wallpaper starts and so it reverts to the
> default setting when null is returned (see code below).  As I say,
> this problem has only been introduced with Froyo as Eclair works fine
> (the image is found and used so the internal storage must be mounted
> before the Live Wallpaper starts).  Here's the code that searches for
> the CustomBG.jpg image on startup...
>
>         @Override
>         public void onSurfaceCreated(SurfaceHolder holder) {
>                 super.onSurfaceCreated(holder);
>                 c = holder.lockCanvas();
>                 canvasSize = new Point(c.getWidth(), c.getHeight());
>                 globalCanvasSize = canvasSize;
>                 holder.unlockCanvasAndPost(c);
>                 generateBackgroundGraphic();
>         }
>
>         private void generateBackgroundGraphic() {
>                 if (backgroundToJPG() == null) {    //default to gradient
> pattern
>                         background = BitmapFactory.decodeResource(res, 
> R.raw.gradient);
>                         Log.d("pic", "(SF) File doesn't exist to using 
> Gradient as
> default");
>                 } else {
>                         background =
> BitmapFactory.decodeFile(backgroundToJPG().getPath());
>                         Log.d("pic", "(SF) File does exist so using 
> '/Snowflakes/
> CustomBG.jpg' as background");
>                 }
>         }
>
>         private File backgroundToJPG() {
>                 String status = Environment.getExternalStorageState();
>                 if (status.equals(Environment.MEDIA_MOUNTED)) {
>                         File d = new 
> File(Environment.getExternalStorageDirectory()
> +"/Snowflakes");
>                         d.mkdirs();
>                         File f = new File(d,"CustomBG.jpg");
>                         if (!f.exists()) {return null;}
>                         return f;                                  // <-- 
> FILE NOT
> BEING RETURNED HERE!!
>                 }
>         }
>
> Apologies for the code formatting - is there any way I can improve
> this?  Anyway, I'd be very grateful for any help you may have... I
> can't find any information about this on-line so perhaps there's
> something wrong with my code?
>
> Thanks, Chris

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