android - Taking a picture and storing it to internal storage -


i'm trying take picture , when user clicks button, want save picture internal storage. testing on tablet not have sd card. i'm new taking pictures on android , web has been no trying find specific code need write somewhere other sd card. here camera.java looks like.

package com.test;  import com.test.r;  import java.io.filenotfoundexception; import java.io.fileoutputstream; import java.io.ioexception;  import android.app.activity;  import android.hardware.camera; import android.hardware.camera.picturecallback; import android.hardware.camera.shuttercallback;  import android.os.bundle;  import android.util.log; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.framelayout;  public class camera extends activity {     private static final string tag = "camerademo";         camera camera;         preview preview;         button buttonclick;      /** called when activity first created. */     @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.camera);          preview = new preview(this);         ((framelayout) findviewbyid(r.id.preview)).addview(preview);          buttonclick = (button) findviewbyid(r.id.buttonclick);         buttonclick.setonclicklistener( new onclicklistener() {             public void onclick(view v) {                 preview.camera.takepicture(shuttercallback, rawcallback, jpegcallback);             }         });          log.d(tag, "oncreate'd");     }       shuttercallback shuttercallback = new shuttercallback() {         public void onshutter() {             log.d(tag, "onshutter'd");         }     };      /** handles data raw picture */     picturecallback rawcallback = new picturecallback() {         public void onpicturetaken(byte[] data, camera camera) {             log.d(tag, "onpicturetaken - raw");         }     };      /** handles data jpeg picture */     picturecallback jpegcallback = new picturecallback() {         public void onpicturetaken(byte[] data, camera camera) {             fileoutputstream outstream = null;             try {                 // write local sandbox file system                 outstream = camera.this.openfileoutput(string.format("%d.jpg", system.currenttimemillis()), 0);                  // or write sdcard                 //outstream = new fileoutputstream(string.format("/sdcard/%d.jpg", system.currenttimemillis()));                     outstream.write(data);                 outstream.close();                 log.d(tag, "onpicturetaken - wrote bytes: " + data.length);             } catch (filenotfoundexception e) {                 e.printstacktrace();             } catch (ioexception e) {                 e.printstacktrace();             } {             }             log.d(tag, "onpicturetaken - jpeg");         }     };  } 

it's not clear kind of problem you're getting code. way you're opening file seems fine, maybe it's behaving in way that's incorrect?

this page in android document has details using different kinds of storage available application: http://developer.android.com/guide/topics/data/data-storage.html

in particular, section saving files should shared might useful situation. references "external storage" many devices simulate external storage using internal storage, developer don't need worry it.

if want picture viewable in system's gallery app, can add media scanning using mediascannerconnection.scanfile. may not work, though, if storing files in app's private storage openfileoutput.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -