国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 調用系統照相機拍照和錄像

2019-12-12 05:20:12
字體:
來源:轉載
供稿:網友

本文實現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/

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 四川省| 双峰县| 榆林市| 惠州市| 福清市| 蓬安县| 山丹县| 浮梁县| 三门峡市| 小金县| 繁昌县| 石柱| 甘南县| 吕梁市| 龙山县| 高青县| 岳普湖县| 遵义县| 轮台县| 东光县| 图片| 长宁县| 湖北省| 玛纳斯县| 公安县| 宜昌市| 平安县| 永康市| 浮梁县| 商城县| 时尚| 苍溪县| 介休市| 慈利县| 同仁县| 广元市| 黄石市| 达孜县| 武夷山市| 读书| 南丹县|