Android APP崩溃(从相机拍摄照片后)

时间:2012-09-26 09:28:58

标签: android upload android-camera

我从我的APP开始使用相机。有时我的应用程序在捕获图像后恢复我的应用程序时崩溃了。我的APP又重新推出了。

我该怎么做才能处理这种类型的崩溃。

public void onClick(View view)
{
    // TODO Auto-generated method stub

    if(view==btnAddPrescription)
    {
        Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
        File photo=getOutputMediaFile(MEDIA_TYPE_IMAGE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
        imageUri = Uri.fromFile(photo);
        Log.v("Image URI", imageUri.toString());

        startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }
}

public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    Log.v("requestCode",requestCode+"");
    Log.v("resultCode",resultCode+"");

    if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE)
    {
        if (resultCode == RESULT_OK)
        {
            selectedImageUri = imageUri;
            newPictPath=selectedImageUri.getPath();
            this.setSelectedPath(newPictPath);
            Log.v("newPictPath",newPictPath);
            getContentResolver().notifyChange(selectedImageUri, null);
            ImageView imageView = (ImageView) findViewById(R.id.img_prescription);
            ContentResolver cr = getContentResolver();
            Bitmap bitmap;
            try
            {
                bitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, selectedImageUri);
                imageView.setImageBitmap(bitmap);
                //Toast.makeText(this, selectedImageUri.toString(),Toast.LENGTH_LONG).show();
            }
            catch (Exception e)
            {
                Toast.makeText(this, "Failed to load", Toast.LENGTH_SHORT).show();
                Log.e("Camera", e.toString());
            }
        }
        else if (resultCode == RESULT_CANCELED) 
        {
            // User cancelled the image capture
        }
        else 
        {
            // Image capture failed, advise user
        }//else ends here
    }//if ends here
}

我正在使用此代码。它在模拟器上正常工作。但是,当我在设备上运行它时,有时它会因抛出java.lang.RuntimeException而崩溃:将结果ResultInfo {who = null,request = 0,result = -1,data = null}传递给此异常活动失败。

0 个答案:

没有答案
相关问题