2014-08-28 59 views
0

在上帝的名義數據上的活動的結果無效,從相機中某些設備

嗨,

我用這個鱈魚拍攝照片:

private void takePicture() { 

      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

      try { 
       Uri mImageCaptureUri = null; 
       String state = Environment.getExternalStorageState(); 
       if (Environment.MEDIA_MOUNTED.equals(state)) { 
        mImageCaptureUri = Uri.fromFile(mFileTemp); 
       } 
       else { 
        /* 
        * The solution is taken from here: http://stackoverflow.com/questions/10042695/how-to-get-camera-result-as-a-uri-in-data-folder 
        */ 
        mImageCaptureUri = InternalStorageContentProvider.CONTENT_URI; 
       } 
       intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri); 
       intent.putExtra("return-data", true); 
       startActivityForResult(intent, REQUEST_CODE_TAKE_PICTURE); 
      } catch (ActivityNotFoundException e) { 

       Log.d(DBAdapter.TAG, "cannot take picture", e); 
      } 
     } 

這是一些設備良好但在其他一些設計這不工作和數據onActivityResult我null,我真的不知道該怎麼做。我在github上和計算器非常搜查,但還是沒有找到任何答案:(

+0

可以顯示日誌貓嗎? – Ramz 2014-08-28 17:33:37

+0

不,因爲沒有問題在模擬器和它的設備是未知的日食:(但我知道這個問題是與內存不足 – 2014-08-28 17:41:27

+1

「這不工作」太泛泛解決; ** null **數據在'onActivityResult )'在某些設備上是正常的;無論如何,數據只會給你一個捕獲圖像的縮略圖位圖,該位圖可以在列表或網格視圖中使用,但無法填寫屏幕 – 2014-09-01 15:43:33

回答

0

請試試這個.....

private static final int cameraRequest = 10000; 

..........On Button Click................ 

Intent cameraClickIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
      startActivityForResult(cameraClickIntent, cameraRequest); 
.......................................... 


//////////On activity result//////////////////// 

protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == cameraRequest && resultCode == RESULT_OK) { 
     Bitmap photo = (Bitmap) data.getExtras().get("data"); 
     imageView.setImageBitmap(photo); 
    } 
} 

不要忘了添加這些行manisfest文件

<uses-feature android:name="android.hardware.camera"></uses-feature> 
<uses-feature android:name="android.hardware.camera" android:required="false"></uses-feature> 

希望這會對你有所幫助....

相關問題