cant save images on actual device but working on emulator

All your problems with Audio, Video and Images.

cant save images on actual device but working on emulator

Postby scoobasteve1982 » Thu Mar 04, 2010 1:33 am

Hi there,

I've been able to successfully save a snapshot as a JPEG that I take from the camera to my emulator in the "data/data/com.mypackage/files/" folder by doing the following:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. FileOutputStream stream = openFileOutput( "camera_photo.jpg", MODE_WORLD_READABLE );
  5.  
  6.  
  7.  
  8. Bitmap usrPic = BitmapFactory.decodeByteArray(data, 0, data.length);
  9.  
  10.  
  11.  
  12. usrPic.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  13.  
  14.  
  15.  
  16. stream.flush();
  17.  
  18.  
  19.  
  20. stream.close();
  21.  
  22.  
  23.  
  24.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


However, when I plug my actual Droid device via USB into my computer and run the application, the file supposedly is written to disk however I can't find it anywhere. I'm using ASTRO file browser app to search the entire device but I can't find it anywhere. I have set the appropriate permissions in my AndroidManifest file by way of:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.  
  2. <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  3.  
  4.  
Parsed in 0.000 seconds, using GeSHi 1.0.8.4


so I'm not really sure what is going on. I tried writing to the SDCard also by changing the filename above to "/sdcard/camera_image.jpg" however I get an exception that says "java.lang.IllegalArgumentException: File sdcard/traffic_life.jpg contains a path separator" both when I try to run on the emulator AND my actual Droid device. Does anyone know what is going on? Ideally I'd just like to write directly to the Sdcard with a folder of my app. I'm not sure how to do this. I've searched everywhere but have found no real solutions. Any help would be greatly appreciated.
scoobasteve1982
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 04, 2010 1:20 am

Top

Postby scoobasteve1982 » Thu Mar 04, 2010 2:07 am

Okay so I've figured it out. In order for this now to work on my emulator I have to set the permissions of my /sdcard/ directory. Otherwise, if I want to save to my actual device I can do this:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. File f = new File(Environment.getExternalStorageDirectory() + "/camera_photo.jpg");
  3.  
  4.  
  5.  
  6. try {
  7.  
  8.   f.createNewFile();
  9.  
  10. } catch (Exception e) {
  11.  
  12.   e.printStackTrace();
  13.  
  14.   System.out.println("CAN WRITE FILE");
  15.  
  16. }
  17.  
  18.  
  19.  
  20. FileOutputStream stream = new FileOutputStream(f);
  21.  
  22.  
  23.  
  24. Bitmap usrPic = BitmapFactory.decodeByteArray(data, 0, data.length);
  25.  
  26.  
  27.  
  28. usrPic.compress(Bitmap.CompressFormat.JPEG, 100, stream);
  29.  
  30.  
  31.  
  32. stream.flush();
  33.  
  34.  
  35.  
  36. stream.close();
  37.  
  38.  
  39.  
  40.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4
scoobasteve1982
Freshman
Freshman
 
Posts: 4
Joined: Thu Mar 04, 2010 1:20 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 9 guests