1

我已经从我的 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} 传递给活动此异常。

4

0 回答 0