2012-12-30 47 views
2

Eclipse在下面的代碼中給TAKE_PICTURE一個錯誤。我嘗試用CAMERA_PIC_REQUEST替換它,並得到相同的錯誤。我正在爲Android 4.2進行開發。用相機拍照Android在Eclipse中出現錯誤

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    File file = new File(Environment.getExternalStorageDirectory(), "test.jpeg"); 
    Uri outputFileUri = Uri.fromFile(file); 

    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
    intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 

    startActivityForResult(intent, TAKE_PICTURE); 
} 

任何想法我必須做什麼?

+1

什麼是錯誤。 – nhaarman

回答

0

我想這是你從什麼地方複製一個不完整的示例代碼,startActivityForResult函數接收將由你自己的應用程序使用後,找出哪些活動剛剛完成一個任意請求的代碼,像這樣:

startActivityForResult(i, 100); 
...  

startActivityForResult(i, 200); 
... 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    if (requestCode == 100){ 
     //First Activity has just finished 
    } 
    if (requestCode == 200){ 
     //Second Activity has just finished 
    } 
} 

所以基本上,你應該在應用程序中爲TAKE_PICTURE定義一個任意值。