2013-07-30 31 views
-3

我是新來的android編程,但已嘗試使用相機應用程序的幾種方法。在Android上使用應用程序寫相機

我想每隔5分鐘拍攝一張照片併發送到我的服務器,但是我嘗試過的每種方法最終都會提供給我一個應用程序,該應用程序會爲我提供內置相機應用程序,並期望我能按下快門。我需要這種自動化

科爾多瓦的'包裝'這樣做。 Android開發人員頁面上的示例執行此操作,並且我在通過Android編程書籍工作時懷疑,相機pp示例也會這樣做。

+1

您有問題嗎?除了「請給我代碼」? – Simon

回答

0
//somewhere in your code call this (Maybe you need to set up a timer): 
mCamera.takePicture(null, null, mCall); 

//this should be done before using camera 
Camera mCamera; 
private boolean safeCameraOpen(int id) { 
boolean qOpened = false; 

    try { 
     releaseCamera(); 
     mCamera = Camera.open(id); 
     qOpened = (mCamera != null); 
    } catch (Exception e) { 
     Log.e(getString(R.string.app_name), "failed to open Camera"); 
     e.printStackTrace(); 
    } 

    return qOpened;  
} 

private void releaseCamera() { 
    if (mCamera != null) { 
     mCamera.release(); 
     mCamera = null; 
    } 
} 

Camera.PictureCallback mCall = new Camera.PictureCallback() { 

    // you need to change this method due to your needs 
    public void onPictureTaken(byte[] data, Camera camera) { 
     //decode the data obtained by the camera into a Bitmap 

     FileOutputStream outStream = null; 
       try { 
        outStream = new FileOutputStream("/sdcard/Image.jpg"); 
        outStream.write(data); 
        outStream.close(); 
       } catch (FileNotFoundException e){ 
        Log.d("CAMERA", e.getMessage()); 
       } catch (IOException e){ 
        Log.d("CAMERA", e.getMessage()); 
       } 

    } 
};