Android Intents,onActivityResult,并将这些结果保存到Parse.com

时间:2014-02-02 00:46:52

标签: android android-intent android-camera parse-platform

我正在尝试使用MediaStore.ACTION_IMAGE_CAPTURE意图捕获照片,但我遇到了一些问题,让它做我想做的事情。我有相机启动,我可以用它拍照,但我需要执行一些不同的操作,具体取决于在什么阶段按下什么按钮。

基本上:

  • 如果在相机意图上并按下“返回”按钮,则退出到活动类
  • 拍照后,如果按Discard,请返回相机意图
  • 拍照后,如果按“保存”,请返回相机意图

在我的活动中,我有一个方法,我从我的onCreate方法调用:

private void dispatchTakePictureIntent() {
    Intent i = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (i.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(i, REQUEST_IMAGE_CAPTURE);
    }
}

这似乎工作正常。我遇到的问题与我的onActivityResult方法有关。

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap image = (Bitmap )extras.get("data");
        // Here is where I'm stuck. The docs I've found 
        // are saying this is only a thumbnail.
        // I need to get it as a byte array, I think.
        dispatchTakePictureIntent(); // I'm getting camera intents stacking
                                     // on top of each other from this
                                     // I think there's a way to close them 
                                     // after launching a new one
    }
    // Here is where I think I need to put the if statement 
    // to handle the Discard resultCode
}
// I'm trying to save the photos and upload them to parse
private void savePhoto(byte[] data) {
    parseFile = new ParseFile(ParseUser.getCurrentUser().getUsername()
        + System.currentTimeMillis() + .jpg", data);
    // Some other parse methods
    parseFile.saveInBackground(new SaveCallBack() {
        // More parse stuff
    });
}

这是我第一次使用相机,所以我一直在阅读Android文档,但我找不到太多帮助。

0 个答案:

没有答案