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通過(guò)單點(diǎn)觸摸移動(dòng)圖片
這篇文章主要為大家詳細(xì)介紹了Android通過(guò)單點(diǎn)觸摸移動(dòng)圖片,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04
Android實(shí)現(xiàn)登錄注冊(cè)界面框架
這篇文章主要介紹了Android實(shí)現(xiàn)登錄注冊(cè)界面的框架,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-09-09
Android仿京東頂部搜索框滑動(dòng)伸縮動(dòng)畫(huà)效果
這篇文章主要為大家詳細(xì)介紹了Android仿京東頂部搜索框滑動(dòng)伸縮動(dòng)畫(huà)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07
Android編程實(shí)現(xiàn)WebView全屏播放的方法(附源碼)
這篇文章主要介紹了Android編程實(shí)現(xiàn)WebView全屏播放的方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了Android實(shí)現(xiàn)WebView全屏播放的布局與功能相關(guān)技巧,需要的朋友可以參考下2015-11-11
Kotlin注解實(shí)現(xiàn)Parcelable序列化流程詳解
有時(shí)我們會(huì)在界面跳轉(zhuǎn)的過(guò)程中,做對(duì)象傳值,這時(shí)就需要對(duì)該對(duì)象做序列化處理了。Android中對(duì)對(duì)象的序列化處理有兩種方式,這篇文章主要介紹了Kotlin注解實(shí)現(xiàn)Parcelable序列化2022-12-12
Android 中的類(lèi)文件和類(lèi)加載器詳情
這篇文章主要介紹了Android 中的類(lèi)文件和類(lèi)加載器詳情,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-06-06
android 傳感器(OnSensorChanged)使用介紹
當(dāng)傳感器的值發(fā)生變化時(shí),例如磁阻傳感器方向改變時(shí)會(huì)調(diào)用OnSensorChanged(). 當(dāng)傳感器的精度發(fā)生變化時(shí)會(huì)調(diào)用OnAccuracyChanged()方法2014-11-11
Android Fragment滑動(dòng)組件ViewPager的實(shí)例詳解
這篇文章主要介紹了Android Fragment滑動(dòng)組件ViewPager的實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-05-05
Android HorizontalScrollView滑動(dòng)與ViewPager切換案例詳解
這篇文章主要介紹了Android HorizontalScrollView滑動(dòng)與ViewPager切換案例詳解,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08
詳解Flutter如何繪制曲線,折線圖及波浪動(dòng)效
這篇文章主要為大家介紹線條類(lèi)圖形的繪制(正弦曲線、折線圖),并且結(jié)合 Animation 實(shí)現(xiàn)了常見(jiàn)的波浪動(dòng)效,感興趣的小伙伴可以了解一下2022-03-03

