美文网首页
调用摄像头进行拍照和摄像

调用摄像头进行拍照和摄像

作者: yanghanbin_it | 来源:发表于2017-06-08 14:55 被阅读0次
    public class MainActivity extends AppCompatActivity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
    
        }
    
        public void image(View v) {
            //启动拍照
            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, 10);
        }
    
        public void audio(View v) {
            //启动摄像
            Intent intent = new Intent();
            intent.setAction(MediaStore.ACTION_VIDEO_CAPTURE);
            //指定保存路径
            intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "haha.3gp")));
    
            // 0:低质量   1:高质量
            intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);
            startActivityForResult(intent, 20);
        }
    
        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
    
            if (requestCode == 10) {
                Toast.makeText(this, "拍照成功", Toast.LENGTH_SHORT).show();
            }
    
            if (requestCode == 20) {
                Toast.makeText(this, "摄像成功", Toast.LENGTH_SHORT).show();
            }
    
        }
    }
    
    

    相关文章

      网友评论

          本文标题:调用摄像头进行拍照和摄像

          本文链接:https://www.haomeiwen.com/subject/duftqxtx.html