我正在尝试使用意图相机在我的应用程序中捕获视频,当我拍摄视频并且我被重定向到主要活动时它工作正常,但是在我按下后退按钮的意图相机模式它崩溃
@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();
}
}
}
}
}
}
答案 0 :(得分:2)
我猜你的摄像机视频意图CODE = RESULT_CODE_COMPRESS_VIDEO。然后将代码替换为
首先将MarkupCompilePass2
更改为reqCOde并使用以下代码
resCode == RESULT_CODE_COMPRESS_VIDEO.
这不会使你的应用程序在从意图相机反向停止时崩溃。
答案 1 :(得分:0)
希望这有帮助!
if (reqCode == RESULT_CODE_COMPRESS_VIDEO) {
if(resCode == RESULT_OK) {
if (uri != null) {
compress();
}
}
else if(resCode == RESULT_CANCELED && data!=null){
Toast.makeText(MainActivity.this,"Error !",Toast.LENGTH_LONG).show();
else return true;
}
}
答案 2 :(得分:0)
if (requestCode == 1) {
if(data !=null){
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
//String path = saveImage(thumbnail);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();
Glide.with(eventPreview.getContext()).load(byteArray).into(eventPreview);
int width = eventPreview.getMeasuredWidth();
eventPreview.getLayoutParams().height = width/2;
eventPreview.setScaleType(ImageView.ScaleType.FIT_XY);
postData = byteArray;
PreviewTXT.setVisibility(View.GONE);}
}