码迷,mamicode.com
首页 > 移动开发 > 详细

Android初级教程调用手机拍照与摄像功能

时间:2016-06-24 15:07:53      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

这个小案例建议在手机上运行。

package com.example.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){
    	Intent intent = new Intent();
    	intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);//查看谷歌api按照其步骤走
    	intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory(),"haha.jpg")));//设置保存路径
    	startActivityForResult(intent, 10);//启动系统拍照功能并返回值
    }
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	// TODO Auto-generated method stub
    	super.onActivityResult(requestCode, resultCode, data);
    	if(requestCode==10){
    		Toast.makeText(this, "拍照成功", 0).show();
    	}if(requestCode==20){
    		Toast.makeText(this, "摄像成功", 0).show();
    	}
    }
    
    public void video(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")));
    	intent.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 1);//设置录像的质量
    	startActivityForResult(intent, 20);
    }
}




Android初级教程调用手机拍照与摄像功能

标签:

原文地址:http://blog.csdn.net/qq_32059827/article/details/51747223

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!