views:

173

answers:

2

I'm trying to crop a photo to use in a Live Wallpaper but I'm getting a FileNotFoundException when the crop activity tries to save my new cropped image. This is the code I'm using:

File file = new File(getFilesDir(), "wallpaper.jpg");

Intent intent = new Intent("com.android.camera.action.CROP");
intent.setData(uri);

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

intent.putExtra("outputX", metrics.widthPixels * 2);
intent.putExtra("outputY", metrics.heightPixels);
intent.putExtra("aspectX", metrics.widthPixels * 2);
intent.putExtra("aspectY", metrics.heightPixels);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra("output", Uri.parse("file:/" + file.getAbsolutePath()));

startActivityForResult(intent, REQUEST_CROP_IMAGE);

The wallpaper.jpg file seems to exist on DDMS file explorer so I'm not sure what I'm doing wrong. Any advice is greatly appreciated.

A: 

http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

If you're using API Level 7 or lower, use getExternalStorageDirectory(), to open a File representing the root of the external storage. You should then write your data in the following directory:

/Android/data//files/ The is your Java-style package name, such as "com.example.android.app". If the user's device is running API Level 8 or greater and they uninstall your application, this directory and all its contents will be deleted.

Alex Volovoy
A: 

getFilesDir() return your application's privte directory. Camera can't access your private directory. To make wallpaper.jpg accessible by Camera place it in some publix folder. For example like Alex said it can be sd card root. The fixed code would be:

File file = new File(Environment.getExternalStorageDirectory(),  "wallpaper.jpg");
Fedor