我不能用ActivityForResult返回previous活动我不、能用、previous、ActivityForResult

由网友(往事)分享简介:我有这些codeS。打开相机,拍摄照片,但是当我点击确定按钮,什么都没有发生。只有这样,才能回到previous活动点击X按钮,这不是我:)有用。有什么问题? (方法的onActivityResult尚未完成)。(我以前用这种算法是 Android.provider.MediaStore.ACTION_IM​​AGE_...

我有这些codeS。打开相机,拍摄照片,但是当我点击确定按钮,什么都没有发生。只有这样,才能回到previous活动点击X按钮,这不是我:)有用。有什么问题? (方法的onActivityResult尚未完成)。(我以前用这种算法是 Android.provider.MediaStore.ACTION_IM​​AGE_CAPTURE 的意图。有一切就OK了。我不知道为什么我现在有问题。)

 公共无效的onClick(视图v){            意图getCameraImage =新意图(android.media.action.IMAGE_CAPTURE);            db.open();            光标CR = db.getAllRecords();            诠释计数= cr.getCount();            db.close();            文件cameraFolder;            如果(android.os.Environment.getExternalStorageState()。等于(android.os.Environment.MEDIA_MOUNTED))                cameraFolder =新的文件(android.os.Environment.getExternalStorageDirectory(),TSFC);            其他                cameraFolder = ShowMessagesPage.this.getCacheDir();            如果(!cameraFolder.exists())                cameraFolder.mkdirs();            文件照片=新的文件(Environment.getExternalStorageDirectory(),TSFC /+(计数+ 1)+.JPG);            getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(照片));            initialURI = Uri.fromFile(照片);            startActivityForResult(getCameraImage,CAMERA_RESULT);        }});}保护无效的onActivityResult(INT申请code,INT结果code,          意向意向){        super.onActivityResult(要求code,结果code,意向);        如果(结果code == RESULT_OK){            捆绑额外= intent.getExtras();            照片=(URI)extras.get(数据);        }      } 

解决方案

确定,它众所周知的Bug,

刚刚加入这个code线, photo.createNewFile();

喜欢的东西,

 文件照片=新的文件(Environment.getExternalStorageDirectory(),TSFC /+(计数+ 1)+.JPG);photo.createNewFile();getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(照片)); 

另外不要忘了,

 <使用许可权的android:NAME =android.permission.WRITE_EXTERNAL_STORAG​​E/> 
eclipse 9.0 工程redeploy出错 加载不了 求解决 急

让我知道你的进度。

I have these codes. Camera opened, the picture is taken, but when I click on "ok" button, nothing happened. The only way to get back to previous activity is clicking the "x" button which is not useful for me :). What is the problem? (onActivityResult method is not finished yet.) (I used to use this algorithm with Android.provider.MediaStore.ACTION_IMAGE_CAPTURE intent. there was everything OK. I have no idea why I have problem now.)

public void onClick(View v) {

            Intent getCameraImage = new Intent("android.media.action.IMAGE_CAPTURE");
            db.open();
            Cursor cr = db.getAllRecords();
            int count = cr.getCount();

            db.close();

            File cameraFolder;

            if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
                cameraFolder = new File(android.os.Environment.getExternalStorageDirectory(),"TSFC");
            else
                cameraFolder= ShowMessagesPage.this.getCacheDir();
            if(!cameraFolder.exists())
                cameraFolder.mkdirs();

            File photo = new File(Environment.getExternalStorageDirectory(), "TSFC/" + (count + 1) + ".jpg");
            getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

            initialURI = Uri.fromFile(photo);

            startActivityForResult(getCameraImage, CAMERA_RESULT);
        }});}

protected void onActivityResult(int requestCode, int resultCode,
          Intent intent) {
        super.onActivityResult(requestCode, resultCode, intent);

        if (resultCode == RESULT_OK) {
            Bundle extras = intent.getExtras();
            photo = (Uri) extras.get("data");


        }
      }

解决方案

Ok, Its well known Bug,

Just Add this code line, photo.createNewFile();

Something like,

File photo = new File(Environment.getExternalStorageDirectory(), "TSFC/" + (count + 1) + ".jpg");
photo.createNewFile();
getCameraImage.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));

Also don't forget to,

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

And let me know your progress.

阅读全文

相关推荐

最新文章