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

首頁 > 系統 > Android > 正文

Android 實現調用系統照相機拍照和錄像的功能

2019-12-12 04:43:09
字體:
來源:轉載
供稿:網友

本文實現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);      }}

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 衡南县| 延寿县| 隆德县| 亳州市| 资中县| 保定市| 雅江县| 库尔勒市| 科尔| 修文县| 卢氏县| 新丰县| 东海县| 嵩明县| 巧家县| 郁南县| 寿宁县| 阜宁县| 平邑县| 噶尔县| 花莲县| 香格里拉县| 望谟县| 洪泽县| 当雄县| 马边| 江孜县| 石城县| 岚皋县| 霍山县| 通榆县| 海原县| 高密市| 屏东县| 大渡口区| 阳西县| 罗江县| 阜新市| 常山县| 土默特左旗| 墨竹工卡县|