Android 調(diào)用系統(tǒng)照相機(jī)拍照和錄像
本文實(shí)現(xiàn)android系統(tǒng)照相機(jī)的調(diào)用來拍照
項(xiàng)目的布局相當(dāng)簡單,只有一個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="調(diào)用系統(tǒng)相機(jī)拍照" /> </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>
相關(guān)代碼如下:
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> */ // 激活系統(tǒng)的照相機(jī)進(jìn)行拍照 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); } }
實(shí)現(xiàn)激活錄像功能的相關(guān)代碼也很簡單:
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> */ // 激活系統(tǒng)的照相機(jī)進(jìn)行錄像 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, "調(diào)用照相機(jī)完畢", 0).show(); super.onActivityResult(requestCode, resultCode, data); } }
出處:http://www.cnblogs.com/wuyudong/
- android 7自定義相機(jī)預(yù)覽及拍照功能
- Android調(diào)用系統(tǒng)照相機(jī)拍照與攝像的方法
- Android如何調(diào)用系統(tǒng)相機(jī)拍照
- Android編程實(shí)現(xiàn)調(diào)用相冊、相機(jī)及拍照后直接裁剪的方法
- Android自定義相機(jī)實(shí)現(xiàn)定時拍照功能
- Android自定義組件獲取本地圖片和相機(jī)拍照圖片
- Android使用系統(tǒng)自帶的相機(jī)實(shí)現(xiàn)一鍵拍照功能
- Android 系統(tǒng)相機(jī)拍照后相片無法在相冊中顯示解決辦法
- Android 實(shí)現(xiàn)調(diào)用系統(tǒng)照相機(jī)拍照和錄像的功能
- Android實(shí)現(xiàn)從本地圖庫/相機(jī)拍照后裁剪圖片并設(shè)置頭像
- Android自定義照相機(jī)倒計(jì)時拍照
- Android啟動相機(jī)拍照并返回圖片
- Android打開系統(tǒng)相機(jī)并拍照的2種顯示方法
相關(guān)文章
Android提高之BroadcastReceiver實(shí)例詳解
這篇文章主要介紹了Android的BroadcastReceiver用法,在Android的項(xiàng)目開發(fā)中是比較實(shí)用的功能,需要的朋友可以參考下2014-08-08解決EditText、ListView以及GridView同時使用,輸入法自動跳出來的方法
本篇文章是對在Android中EditText、ListView以及GridView同時使用,輸入法自動跳出來的解決方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05Android Style.xml的應(yīng)用詳解及代碼實(shí)現(xiàn)
這篇文章主要介紹了Android Style.xml的應(yīng)用詳解及代碼實(shí)現(xiàn)的相關(guān)資料,需要的朋友可以參考下2016-10-10Android自定義實(shí)現(xiàn)可回彈的ScollView
這篇文章主要為大家詳細(xì)介紹了Android自定義實(shí)現(xiàn)可回彈的ScollView,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-04-04Android中獲得正在運(yùn)行的程序和系統(tǒng)服務(wù)的方法
這篇文章主要介紹了Android中獲得正在運(yùn)行的程序和系統(tǒng)服務(wù)的方法,分別是對ActivityManager.RunningAppProcessInfo類和ActivityManager.RunningServiceInfo類的使用,需要的朋友可以參考下2016-02-02Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼
這篇文章主要介紹了Android實(shí)現(xiàn)水波紋擴(kuò)散效果的實(shí)例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-05-05