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

Android 调用系统照相机拍照和录像,第1张

概述本文实现android系统照相机调用拍照项目的布局相当简单,只有一个Button:

本文实现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);      }}

 出处:http://www.cnblogs.com/wuyudong/

总结

以上是内存溢出为你收集整理的Android 调用系统照相机拍照和录像全部内容,希望文章能够帮你解决Android 调用系统照相机拍照和录像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1148264.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存