Android 实现调用系统照相机拍照和录像的功能_Android

本文实现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
调用照相机
用普通照相机拍照时、6s照相机黑屏无法拍照、5s照相机黑屏无法拍照、照相机连接电脑拍照、照相机录像,以便于您获取更多的相关知识。

时间: 2024-08-30 01:47:36

Android 实现调用系统照相机拍照和录像的功能_Android的相关文章

Android 实现调用系统照相机拍照和录像的功能

本文实现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_heig

Android 调用系统照相机拍照和录像_Android

本文实现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_heig

Android 调用系统照相机拍照和录像

本文实现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_heig

代码-android关于调用系统相机拍照后APP闪退的问题

问题描述 android关于调用系统相机拍照后APP闪退的问题 最近在写一个小APP,就是调用系统相机拍照,然后保存在本地相册,代码没有显示bug,但是在调试时出现了拍照后闪退的问题,我的测试机是小米2S,MIUI 7系统,android5.0.X的,拍照的照片能保存在本地,但是在拍照后点击确定后软件就闪退了,这是我的代码 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState)

安卓开发之调用系统照相机拍照并剪辑

调用系统照相机拍照并剪辑 在Android开发过程中,很多时候我们都需要调用照相机拍照,尤其在发布微博的时候. 自己继承Camera类写一个拍照功能显然不是最好的方案,因为我们不能考虑的非常全面. 这个时候,调用系统的照相机无疑是一个很好的解决方法. 下面,我们就写一个调用系统照相机拍照并对照片进行剪辑.    代码如下 复制代码  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  intent.putExtra(Medi

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

系统已经有的东西,如果我们没有新的需求的话,直接调用是最直接的.下面讲讲调用系统相机拍照并保 存图片和如何调用系统相册的方法. 首先看看调用系统相机的核心方法: Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(camera, 100); 相机返回的数据通过下面的回调方法取得,并处理 @Override protected void onActivityResult(int re

android调用系统相机拍照返回图片模糊

问题描述 android调用系统相机拍照返回图片模糊 上传代码 调用系统相机 Intent it = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(it, 1); 然后获取图片 Bundle extras = data.getExtras(); b = (Bitmap) extras.get("data"); String name = new SimpleDateFormat("yyy

Android实现调用系统相册和拍照的Demo示例_Android

本文讲述了Android实现调用系统相册和拍照的Demo示例.分享给大家供大家参考,具体如下: 最近我在群里看到有好几个人在交流说现在网上的一些Android调用系统相册和拍照的demo都有bug,有问题,没有一个完整的.确实是,我记得一个月前,我一同学也遇到了这样的问题,在低版本的系统中没问题,用高于4.4版本的系统就崩溃.所以,我还是想提取出来,给大家整理一下,一个比较完整无bug的demo,让大家收藏,留着以后用. 其实对于调用手机图库,高版本的系统会崩溃,是因为获取方法变了,所以我们应该

Android编程调用系统自带的拍照功能并返回JPG文件示例【附demo源码下载】

本文实例讲述了Android编程调用系统自带的拍照功能返回JPG文件.分享给大家供大家参考,具体如下: package com.eboy.testcamera1; import java.io.File; import java.io.FileOutputStream; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bund