Android 實(shí)現(xiàn)調(diào)用系統(tǒng)照相機(jī)拍照和錄像的功能
本文實(shí)現(xiàn)android系統(tǒng)照相機(jī)的調(diào)用來(lái)拍照
項(xiàng)目的布局相當(dāng)簡(jiǎn)單,只有一個(gè)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>
首先打開(kāi)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)代碼也很簡(jiǎ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); } }
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- android 調(diào)用系統(tǒng)的照相機(jī)和圖庫(kù)實(shí)例詳解
- Android自定義照相機(jī)Camera出現(xiàn)黑屏的解決方法
- android照相、相冊(cè)獲取圖片剪裁報(bào)錯(cuò)的解決方法
- android 照相功能的簡(jiǎn)單實(shí)例
- Android 簡(jiǎn)單的照相機(jī)程序的實(shí)例代碼
- Android自定義照相機(jī)詳解
- 淺談Android 照相機(jī)權(quán)限的聲明
- Android 實(shí)現(xiàn)IOS選擇拍照相冊(cè)底部彈出的實(shí)例
- Android調(diào)用系統(tǒng)照相機(jī)拍照與攝像的方法
- Android實(shí)現(xiàn)簡(jiǎn)單的照相功能
相關(guān)文章
android TextView不用ScrollViewe也可以滾動(dòng)的方法
這篇文章主要介紹了android TextView不用ScrollViewe也可以滾動(dòng)的方法,很簡(jiǎn)單實(shí)用的代碼,大家參考使用吧2013-11-11Android實(shí)現(xiàn)可使用自定義透明Dialog樣式的Activity完整實(shí)例
這篇文章主要介紹了Android實(shí)現(xiàn)可使用自定義透明Dialog樣式的Activity,結(jié)合完整實(shí)例形式分析了Android Activity自定義style的操作步驟與相關(guān)技巧,需要的朋友可以參考下2016-07-07Android實(shí)現(xiàn)底部彈出PopupWindow背景逐漸變暗效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)底部彈出PopupWindow背景逐漸變暗效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10微信小程序電商常用倒計(jì)時(shí)實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了微信小程序電商常用倒計(jì)時(shí)實(shí)現(xiàn)實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-06-06Android 5.0及以上編程實(shí)現(xiàn)屏幕截圖功能的方法
這篇文章主要介紹了Android 5.0及以上編程實(shí)現(xiàn)屏幕截圖功能的方法,結(jié)合實(shí)例形式分析了Android5.0以上實(shí)現(xiàn)截圖功能的相關(guān)類、函數(shù)及權(quán)限控制等操作技巧,需要的朋友可以參考下2018-01-01Android實(shí)現(xiàn)Activity界面切換添加動(dòng)畫(huà)特效的方法
這篇文章主要介紹了Android實(shí)現(xiàn)Activity界面切換添加動(dòng)畫(huà)特效的方法,非常實(shí)用的技巧,需要的朋友可以參考下2014-08-08Android自定義控件案例匯總1(菜單、popupwindow、viewpager)
這篇文章主要介紹了Android自定義控件案例匯總,優(yōu)酷菜單、popupwindow實(shí)現(xiàn)下拉列表、viewpager實(shí)現(xiàn)輪播圖,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-12-12android事件分發(fā)機(jī)制的實(shí)現(xiàn)原理
本篇文章主要介紹了android事件分發(fā)機(jī)制的實(shí)現(xiàn)原理,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09Android實(shí)現(xiàn)簡(jiǎn)易版彈鋼琴效果
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)易版彈鋼琴效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05