title: Using the camera in Background Android
body: <p>I'm trying to get the picture into service from Camera. </p>
  
  <pre><code>@Override
  public void onCreate() {
      super.onCreate();
      //android.os.Debug.waitForDebugger();
  
      myCamera=Camera.open();
  
  
        SurfaceView dummy=new SurfaceView(getApplicationContext());
      try {
          if(myCamera!=null)
          {
              myCamera.setPreviewDisplay(dummy.getHolder());
              myCamera.setPreviewCallback(this);
              Log.i(TAG,"myCamera is not null");
          }
              getFrames();
  
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          Log.e(TAG, "setPreviewDisplay " + e);
      }    
      myCamera.startPreview(); 
  }
  
  
      public void getFrames() {
  
          new Thread(new Runnable() {
  
              public void run() {
  
                      while(flag)
                      {
                          Log.i(TAG, "getFrames");
                          try{
  
                              //method();
                          takePictureNoPreview();
                          Thread.sleep(54);
  
                          } catch (Exception e) {
                              Log.e(TAG, "getFrames thread error: " + e);
                          }
                      }
                       myCamera.release();  
  
              }
          }).start();
      }
  
  
  public void takePictureNoPreview(){
              try{
                Log.i(TAG,"takePictureNoPreview");
                myCamera.takePicture(null, null, getJpegCallback())
              } catch (Exception e) {
                  Log.e(TAG, "takePictureNoPreview " + e);
              }
  
  
       private PictureCallback getJpegCallback(){
                  PictureCallback jpeg=new PictureCallback() {   
                    @Override
                    public void onPictureTaken(byte[] data, Camera camera) {
                      try {
                        Log.i(TAG,"getJpegCallback");
                        FileOutputStream(String.format("/sdcard/RealSpeaker/%d.jpg", System.currentTimeMillis()));
                        FileOutputStream os = new FileOutputStream(String.format("/sdcard/Sample/%d.jpg", System.currentTimeMillis()));
                           os.write(data);
                           os.close();
                      }  catch (IOException e) {
                        //do something about it
                      }
                    }
                  };
                  return jpeg;
  
                }
  </code></pre>
  
  <p>The problem is that the method getJpegCallback around is incorrect: (no logs and images in a folder)ю
  When i'm debugging application, TAG - <strong>getJpegCallback</strong> do not show in LogCat, but TAG <strong>takePictureNoPreview</strong>  shows. And after closing application, Camera dont allow(now it's no problem). What's wrong?</p>