【发布时间】:2016-05-01 14:04:02
【问题描述】:
我正在尝试使用意图相机在我的应用程序中捕获视频,当我拍摄视频并被重定向到主要活动时,它一切正常,但是在我在意图相机模式下按下后退按钮后它崩溃了
p>@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
protected void onActivityResult(int reqCode, int resCode, Intent data) {
if (reqCode == REQUEST_CODE_UPDATE_PIC) {
if (resCode == RESULT_OK) {
String imagePath = data.getStringExtra(GOTOConstants.IntentExtras.IMAGE_PATH);
showCroppedImage(imagePath);
Bitmap bitmap;
bitmap = BitmapFactory.decodeFile(imagePath);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);
byte[] image = stream.toByteArray();
// Create the ParseFile
ParseFile file = new ParseFile("profilepic.png", image);
// Upload the image into Parse Cloud
file.saveInBackground();
// Create a column named "ImageFile" and insert the image
user.put("profilepictures", file);
user.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
Toast.makeText(getApplicationContext(), "Saved Successfully",
Toast.LENGTH_SHORT).show();
}
});
// Show a simple toast message
Toast.makeText(MainActivity.this, "Image Uploaded",
Toast.LENGTH_SHORT).show();
} else if (resCode == RESULT_CANCELED) {
//TODO : Handle case
} else {
String errorMsg = data.getStringExtra(ImageCropActivity.ERROR_MSG);
Toast.makeText(this, errorMsg, Toast.LENGTH_LONG).show();
}
}
if (mediaFile != null) {
compress();
}
if (resCode == Activity.RESULT_OK && data != null) {
uri = data.getData();
if (uri == null) {
Toast.makeText(getApplicationContext(), "uri blank", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "uri full", Toast.LENGTH_LONG).show();
}
//proceedbutton.setVisibility(View.VISIBLE);
if (resCode == RESULT_CODE_COMPRESS_VIDEO) {
if (uri != null) {
Cursor cursor = getContentResolver().query(uri, null, null, null, null, null);
try {
if (cursor != null && cursor.moveToFirst()) {
String displayName = cursor.getString(
cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
Log.i(TAG, "Display Name: " + displayName);
int sizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
String size = null;
if (!cursor.isNull(sizeIndex)) {
size = cursor.getString(sizeIndex);
} else {
size = "Unknown";
}
Log.i(TAG, "Size: " + size);
tempFile = FileUtils.saveTempFile(displayName, this, uri);
editText.setText(mediaFile.getPath());
}
} finally {
if (cursor != null) {
cursor.close();
}
}
}
}
}
}
【问题讨论】:
-
了解您遇到了什么崩溃以及您在哪些设备上测试此代码将非常有帮助
-
使用 LogCat 检查与您的崩溃相关的 Java 堆栈跟踪:stackoverflow.com/questions/23353173/…
标签: java android android-intent parse-platform