2012-11-03 83 views
0

我知道這已被問到,但我一直在淘金正確的解決方案,我的問題。我使用相機意圖,然後嘗試從相機中獲取圖像並將其設置爲圖像視圖。一切都很好,直到回到原位並設置圖像。我可以拍照,但當我點擊確定後,它會重新啓動沒有圖像的應用程序。任何想法如何讓它實際捕捉圖像,而不只是重新啓動?安卓相機設置圖像

public class Submit extends Activity { 
    private static final int CAMERA_REQUEST = 1888; 
    private ImageView imageView; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.submit); 
     this.imageView = (ImageView) this.findViewById(R.id.imageView); 
     Button photoButton = (Button) this.findViewById(R.id.photoButton); 
     photoButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
       startActivityForResult(cameraIntent, CAMERA_REQUEST); 
      } 
     }); 
    } 

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

回答

0

將您的CAMERA_REQUEST更改爲1337.它對我有用。

編輯: 現在我查了一下,它也適用於1888年代碼。

你的代碼適合我。