用android相机意图拍照后丢失图像

时间:2015-10-05 08:50:46

标签: java android android-intent android-camera

我开发了一款使用相机意图拍照的应用。然后在拍照后我将调整照片大小并将其移动到应用程序的目录中。并且还保存缩略图大小的照片。在所有过程之后,我将删除DCIM目录中的照片,以便用户无法修改照片。

现在我的问题是一些用户据说他们拍摄的所有照片都丢失了。检查所有应用程序目录时,实际上没有保存照片,并且没有保存DCIM中的照片。我确实尝试复制场景但我无法重新创建它。

这是启动相机意图后的代码:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
    String f = null;
     Bitmap bitmap = null;
     long fileSize = 0;
    if (requestCode == CAMERA_REQUEST){

        if (resultCode == RESULT_OK){

            try {
                if (data!=null){

                    Uri selectedImage = data.getData();
                    SharedPreferences prefs = getSharedPreferences("PHOTO", MODE_PRIVATE); 
                    //String restoredText = prefs.getString("text", null);

                      f = prefs.getString("filename", fileName);//"No name defined" is the default value.
                      int  tvID = prefs.getInt("textView", tv.getId());
                        int  imgID = prefs.getInt("imageView", imageView.getId());

                    //Uri selectedImage = Uri.fromFile(new File(fullFileName)); 


                    tmpDir =  Environment.getExternalStorageDirectory() + "/" +
                            getResources().getString(R.string.tmpPhotoDirectory);
                    photoDir = Environment.getExternalStorageDirectory() + "/" +
                            getResources().getString(R.string.photoDirectory);
                    fullThumbnailName= Environment.getExternalStorageDirectory() + "/" +
                            getResources().getString(R.string.thumbnailDirectory);
                    fullBackupPath =
                                    getResources().getString(R.string.backupPhotoDirectory);


                    if (selectedImage!=null){
                        //ctx.getContentResolver().notifyChange(selectedImage, null);
                        if (ctx == null){
                            System.out.println("CTX is null");
                            ctx = BN38JEstateInspection.getContext();
                        }
                        ContentResolver cr = ctx.getContentResolver(); 
                        System.out.println("Selected Image:" + selectedImage.getPath());
                        Log.i("Result", f);

                        bitmap = android.provider.MediaStore.Images.Media 
                        .getBitmap(cr, selectedImage);
                        saveBitmapToExtCard(bitmap, f);



                        //scaled = ShrinkBitmap(getRealPathFromURI(ctx,selectedImage),  PIC_WIDTH, PIC_HEIGHT,bitmap);
                        fileSize = savePicture(tmpDir + "/" + f, bitmap, PIC_WIDTH, PIC_HEIGHT);
                        if (fileSize > 0){
                            //bitmap = ShrinkBitmap(getRealPathFromURI(ctx,selectedImage),  THUMB_PIC_WIDTH, THUMB_PIC_HEIGHT,bitmap);
                            savePicture(fullThumbnailName + "/" + f.replace("tmp_", ""), bitmap, THUMB_PIC_WIDTH, THUMB_PIC_HEIGHT);
                            tv = (TextView) findViewById(tvID);
                            tv.setText(f.replace(".tmp_", ""));
                            defaultPhoto = f.replace(".tmp_", "");
                             imageView = (ImageView) findViewById(imgID);
                            imageView.setImageBitmap(BitmapFactory.decodeFile(fullThumbnailName + "/" + f.replace("tmp_", "")));
                            Toast.makeText(ctx, "Photo Saved",Toast.LENGTH_LONG).show();
                        }else{
                            tv.setText(defaultPhoto);
                            fileName = defaultPhoto;
                            imageView.setImageBitmap(null);
                            Toast.makeText(ctx, "Error Saving Photo. Kindly retake photo.",Toast.LENGTH_LONG).show();
                        }
                       deleteImageFromDCIM();
                        //System.out.println("Image Name:" + getLastImage());
                    }else{
                        Toast.makeText(ctx, "Null Error Saving Photo. Kindly retake photo.",Toast.LENGTH_SHORT).show();
                    }
                }else{
                    Toast.makeText(ctx, "Null Error Saving Photo. Kindly retake photo.",Toast.LENGTH_SHORT).show();
                }
            } catch (Exception e)
            {
                tv.setText(defaultPhoto);
                fileName = defaultPhoto;
                imageView.setImageBitmap(null);
                Log.e("ERROR " +  TAG, "onActivityResult " + e.toString());
                e.printStackTrace();
            }
        }else{
            //super.onActivityResult(requestCode, resultCode, data);
            Toast.makeText(ctx, "Error Saving Photo. Kindly retake photo.",Toast.LENGTH_SHORT).show();
        }
        if (bitmap != null)
        {
            bitmap.recycle();
        }

    }

你们有没有人有同样的问题?

他们在笔记1中使用的手机升级为软糖。其他用户使用笔记3棒棒糖,并没有遇到问题。

这是一个豆荚问题还是电话问题?

感谢。

0 个答案:

没有答案