本文实现android系统照相机的调用来拍照

项目的布局相当简单,只有一个Button:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" > <Button
android:onClick="click"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="调用系统相机拍照" /> </RelativeLayout>

首先打开packages\apps\Camera文件夹下面的清单文件,找到下面的代码:

       <activity android:name="com.android.camera.Camera"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
android:screenOrientation="landscape"
android:clearTaskOnLaunch="true"
android:taskAffinity="android.task.camera">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.IMAGE_CAPTURE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.media.action.STILL_IMAGE_CAMERA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>

相关代码如下:

public class MainActivity extends Activity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void click(View view) {
/*
* <intent-filter> <action
* android:name="android.media.action.IMAGE_CAPTURE" /> <category
* android:name="android.intent.category.DEFAULT" /> </intent-filter>
*/
// 激活系统的照相机进行拍照
Intent intent = new Intent();
intent.setAction("android.media.action.IMAGE_CAPTURE");
intent.addCategory("android.intent.category.DEFAULT"); //保存照片到指定的路径
File file = new File("/sdcard/image.jpg");
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivity(intent); } }

实现激活录像功能的相关代码也很简单:

public class MainActivity extends Activity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void click(View view) {
/*
* <intent-filter> <action
* android:name="android.media.action.VIDEO_CAPTURE" /> <category
* android:name="android.intent.category.DEFAULT" /> </intent-filter>
*/
// 激活系统的照相机进行录像
Intent intent = new Intent();
intent.setAction("android.media.action.VIDEO_CAPTURE");
intent.addCategory("android.intent.category.DEFAULT"); // 保存录像到指定的路径
File file = new File("/sdcard/video.3pg");
Uri uri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri); startActivityForResult(intent, 0);
} @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Toast.makeText(this, "调用照相机完毕", 0).show();
super.onActivityResult(requestCode, resultCode, data); } }

Android 调用系统照相机拍照和录像的更多相关文章

  1. android 调用系统照相机拍照后保存到系统相册,在系统图库中能看到

    需求:  调用系统照相机进行拍照,并且保存到系统相册,调用系统相册的时候能看到   系统相册的路径:String cameraPath= Environment.getExternalStorageD ...

  2. Android 调用系统相机拍照保存以及调用系统相册的方法

    系统已经有的东西,如果我们没有新的需求的话,直接调用是最直接的.下面讲讲调用系统相机拍照并保存图片和如何调用系统相册的方法. 首先看看调用系统相机的核心方法: Intent camera = new ...

  3. Android调用系统照相机

    ndroid调用系统相机实现拍照功能 在实现拍照的功能时遇到了很多问题,搜索了很多资料,尝试了很多办法,终于解决了,下面简要的描述下在开发过程中遇到的问题. 虽然之前看过android开发的书,但是没 ...

  4. [android] 调用系统照相机和摄像机

    查看系统照相机源码,找到清单文件查看 查看意图过滤器,action是android.media.action.IMAGE_CAPTURE category是android.intent.categor ...

  5. Android调用系统相机拍照保存照片很小解决方案

    保存图片小的一般操作步骤: 1. 调用系统相机 Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityFo ...

  6. android 调用系统相机拍照 获取原图

      好吧,为了这个问题又折腾了一整天.之前在网上找来的方法,如果在onActivityResult中直接用data.getData()的方式来生成bitmap,其实获取的是拍照生成的缩略图!看看尺寸就 ...

  7. Android 调用系统相机拍照,生命周期重走OnCreate,导致无数据的解决办法

    extends:http://blog.csdn.net/b275518834/article/details/42347903 BUG具体体现为 : (1) 摄像头拍照后图片数据不一定能返回 ; o ...

  8. Android 调用系统相机拍照并获取原图

    第一步:调用相机 Intent getImageByCamera = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE); St ...

  9. android调用系统相机拍照并保存在本地

    import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import j ...

随机推荐

  1. 第16/24周 SQL Server 2014中的基数计算

    大家好,欢迎回到性能调优培训.上个星期我们讨论在SQL Server里基数计算过程里的一些问题.今天我们继续详细谈下,SQL Server 2014里引入的新基数计算. 新基数计算 SQL Serve ...

  2. 理解TCP/IP三次握手与四次挥手的正确姿势

    背景 注:以下情节纯属虚构,我并没有女朋友==. 和女朋友异地恋一年多,为了保持感情我提议每天晚上视频聊天一次. 从好上开始,到现在,一年多也算坚持下来了. 问题 有时候聊天的过程中,我的网络或者她的 ...

  3. Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive.

    调试网站时,异常出现:Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive. S ...

  4. 【FTP】在自己的电脑上建立FTP服务器

    <1> 添加新用户: “计算机”点击右键 “管理”得到: 点击“本地用户和组”,点击“用户”: 右键 “新用户”: 设定用户名与密码,这是以后连FTP服务器时用的登录用户名与密码. < ...

  5. C#连接Excel示例代码和驱动

    代码如下: string fileExt = Path.GetExtension(excelPath); string conn = ""; if (fileExt == &quo ...

  6. Apache+PHP 配置随笔

    准备安装包 1:安装VC++ 2012(vcredist_x64,我这边服务器为64位) 2:Apache安装包,php安装包 安装后配置工作 1:安装Apache服务,配置环境变量 httpd -k ...

  7. linq查询xml

    1.加载xml字符串 XElement root = XElement.Parse(@"<?xml version='1.0' encoding='utf-8'?> <It ...

  8. 怎样实现了捕获应用中的日志在android开发中

    怎样实现了捕获应用中的日志在android开发中,大家可研究一下. Process mLogcatProc = null; BufferedReader reader = null; try { mL ...

  9. PHP高效率写法

    1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍.当然了,这个测试方法需要在十万级以上次执行,效果才明显.其实静态方法和非静态方法的效率 ...

  10. Oracle 数据库基础学习 (五) 多表查询

    多表查询:查询结果需要用到两个或者以上表,此时需要多表连接,产生多表查询 1.内连接(等值连接) 示例:将两个表内容连接显示 select * from dept d, emp e where d.d ...