android99 拍照摄像

时间:2024-09-11 23:03:56
package com.itheima.camera;

import java.io.File;

import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Toast; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void image(View v){
//启动系统提供的拍照activity
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "haha.jpg")));//照片路径
startActivityForResult(intent, );
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == ){
Toast.makeText(this, "拍照成功", ).show();
}
else if(requestCode == ){
Toast.makeText(this, "摄像成功", ).show();
}
} public void video(View v){
//启动系统提供的摄像activity
Intent intent = new Intent();
intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "haha.3gp")));//视频路径
intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, );
startActivityForResult(intent, );
} }