Android:使用默认录像机录制并返回sd卡路径
我正在尝试开发一个应用程序,它使用默认应用程序记录视频并写入 SD 卡,然后将 SD 卡路径返回到之前的活动。为什么它对我不起作用?当我点击相机中的后退按钮时,我总是被取消吐司。
public class AndroidVideoActivity extends Activity {
final static int REQUEST_VIDEO_CAPTURED = 1;
Uri uriVideo = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVideoRecorder = (Button) findViewById(R.id.buttonClick);
btnVideoRecorder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_VIDEO_CAPTURED) {
uriVideo = data.getData();
Toast.makeText(AndroidVideoActivity.this, uriVideo.getPath(),
Toast.LENGTH_LONG).show();
}
} else if (resultCode == RESULT_CANCELED) {
uriVideo = null;
Toast.makeText(AndroidVideoActivity.this, "Cancelled!",
Toast.LENGTH_LONG).show();
}
}
}
I'm trying to develop an application which records the video using default application and writes to sd card and then return the sd card path to previous activity. Why it is not working for me?? i'm getting cancelled toast all the time when I click back button in the camera.
public class AndroidVideoActivity extends Activity {
final static int REQUEST_VIDEO_CAPTURED = 1;
Uri uriVideo = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btnVideoRecorder = (Button) findViewById(R.id.buttonClick);
btnVideoRecorder.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent("android.media.action.VIDEO_CAMERA");
startActivityForResult(intent, REQUEST_VIDEO_CAPTURED);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_VIDEO_CAPTURED) {
uriVideo = data.getData();
Toast.makeText(AndroidVideoActivity.this, uriVideo.getPath(),
Toast.LENGTH_LONG).show();
}
} else if (resultCode == RESULT_CANCELED) {
uriVideo = null;
Toast.makeText(AndroidVideoActivity.this, "Cancelled!",
Toast.LENGTH_LONG).show();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不必点击后退按钮 - 后退按钮 = 取消。您应该能够录制视频,当您停止录制时,您应该按“完成”或类似的按钮(我只使用相机完成此操作,而不是视频),然后它将自动返回到您的应用程序。
You shouldn't have to hit the back button - the back button = cancel. You should be able to record the video, and when you stop recording, you should press 'Done' or something similar (I've only done this with camera, not video), and then it will return to your app automatically.