2013-04-09 69 views
0

我用4.0的許多代碼和所有的工作,但果凍豆鋨不支持任何代碼如何在OS 4.2.2安卓

try 
        { 
     Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 

     startActivityForResult(cameraIntent, 1);   
        } 
        catch(ActivityNotFoundException anfe){ 
        //display an error message 
    //     String errorMessage = "Whoops - your device doesn't support capturing images!"; 
        Toast toast= Toast.makeText(getApplicationContext(), "Whoops - your device doesn't support capturing images!", Toast.LENGTH_SHORT); 
        toast.setGravity(Gravity.CENTER, 0, 0); 
        toast.show(); 

       } 

回答

3

在你的onCreate或上一個按鈕

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(cameraIntent, CAMERA_REQUEST); 



private void startActivityForResult(Intent data, int requestCode) { 
    // TODO Auto-generated method stub 
if (requestCode == CAMERA_REQUEST) { 

    Bitmap photo = (Bitmap) data.getExtras().get("data"); 
    yourActivity.pictureImg.setImageBitmap(photo); 
} 

if (requestCode == SELECT_PICTURE) { 
    Uri selectedImageUri = data.getData(); 
    //OI FILE Manager 
    filemanagerstring = selectedImageUri.getPath(); 
    //MEDIA GALLERY 
    selectedImagePath = getPath(selectedImageUri); 
    photo = BitmapFactory.decodeFile(selectedImagePath); 
    yourActivity.pictureImg.setImageBitmap(photo); 

} 
} 
+0

thanx的反應,我用你的代碼只找到墜毀的消息「不幸的是相機已經關閉」 – vabhavsingh 2013-04-09 10:44:36

+0

我做了很多的應用程序相關的攝像頭,但我的代碼是不是在果凍豆兄弟工作 – vabhavsingh 2013-04-09 10:45:16

+0

重新啓動您的手機,然後再試一次。 – 2013-04-09 10:48:47

0

我想你已經忘了在添加權限打開相機清單文件我不知道O的想法,但在Android中它就像它

<uses-permission android:name="android.permission.CAMERA"/> 
+0

我用的T點擊添加該代碼他的許可 – vabhavsingh 2013-04-09 10:30:27