2017-02-02 99 views
-2

我有qrReader應用程序,所以在ActivityResult我寫入意圖到相機,如果我有迴應我想要的是有可能在意圖後自動拍攝照片和自動對焦後??(我應該有什麼增加對自動捕獲)從相機自動捕捉圖像?

 button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      IntentIntegrator intentIntegrator = new IntentIntegrator(activity); 
      intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES); 
      intentIntegrator.setPrompt("Scan"); 
      intentIntegrator.setCameraId(0); 
      intentIntegrator.setBeepEnabled(false); 
      intentIntegrator.setBarcodeImageEnabled(false); 
      intentIntegrator.initiateScan(); 

     } 
    }); 
} 

@Override 
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { 
    final IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data); 
    if(result!= null){ 
       if(result.getContents()==null){ 
        Toast.makeText(getApplicationContext(),"you canceled the scanning",Toast.LENGTH_LONG).show(); 
       } 
       else { 
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        textView.setText(result.getContents()); 
        startActivityForResult(intent, TAKE_PICTURE); 



       } 



    } 

    super.onActivityResult(requestCode, resultCode, data); 
} 
+0

發佈您的代碼,所以我們可以提出修改建議 – Akshay

+0

加入請檢查它還有什麼要補充拍攝的圖片自動 – EasyE

回答

0

添加以下代碼:

寫方法

public void capturePhoto() throws Exception { 
     mCamera.takePicture(shutterCallback, rawCallback, jpegCallback); 
     Thread.sleep(WAIT_GENERIC); 
     mCamera.stopPreview(); 
     mCamera.release(); 
    } 

,並呼籲它在其他的onResult爲

button.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      IntentIntegrator intentIntegrator = new IntentIntegrator(activity); 
      intentIntegrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES); 
      intentIntegrator.setPrompt("Scan"); 
      intentIntegrator.setCameraId(0); 
      intentIntegrator.setBeepEnabled(false); 
      intentIntegrator.setBarcodeImageEnabled(false); 
      intentIntegrator.initiateScan(); 

     } 
    }); 
} 

@Override 
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { 
    final IntentResult result = IntentIntegrator.parseActivityResult(requestCode,resultCode,data); 
    if(result!= null){ 
       if(result.getContents()==null){ 
        Toast.makeText(getApplicationContext(),"you canceled the scanning",Toast.LENGTH_LONG).show(); 
       } 
       else { 
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
        capturePhoto(); 
        textView.setText(result.getContents()); 
        startActivityForResult(intent, TAKE_PICTURE); 



       } 



    } 

在相機中previewclass回答你的問題補充:

ShutterCallback shutterCallback = new ShutterCallback() { 
     public void onShutter() { 
      //   Log.d(TAG, "onShutter'd"); 
     } 
    }; 

    PictureCallback rawCallback = new PictureCallback() { 
     public void onPictureTaken(byte[] data, Camera camera) { 
      //   Log.d(TAG, "onPictureTaken - raw"); 
     } 
    }; 

    PictureCallback jpegCallback = new PictureCallback() { 
     public void onPictureTaken(byte[] data, Camera camera) { 
      new SaveImageTask().execute(data); 
      resetCam(); 
      Log.d(TAG, "onPictureTaken - jpeg"); 
     } 
}; 
+0

什麼是攝像機。 ..? – EasyE

+0

假設你已經初始化了相機,我已經給你這個代碼。 – Akshay

+0

不,這是我的代碼,我只是添加了相機的意圖,即使我沒有photohandler類 – EasyE