Android 7.0 获取相机拍照图片,适配三星手机拍照,解决三星手机拍照屏幕旋转,判断设备是否有摄像头
生活随笔
收集整理的這篇文章主要介紹了
Android 7.0 获取相机拍照图片,适配三星手机拍照,解决三星手机拍照屏幕旋转,判断设备是否有摄像头
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
方法1
新建/res/xml/file_paths:
?
<?xml version="1.0" encoding="utf-8"?> <paths xmlns:android="http://schemas.android.com/apk/res/android"><external-path name="external_files" path="."/> </paths>配置manifest文件
?
?
<providerandroid:name="android.support.v4.content.FileProvider"android:authorities="com.hunuo.yohoo.provider" //com.hunuo.yohoo=包名android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/provider_paths"/> </provider>開始拍照
Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); //系統(tǒng)常量, 啟動(dòng)相機(jī)的關(guān)鍵 startActivityForResult(openCameraIntent, REQUEST_CODE_TAKE_PICTURE); // 參數(shù)常量為自定義的request code, 在取返回結(jié)果時(shí)有用?
拍照返回圖片
Bitmap bm = (Bitmap) data.getExtras().get("data"); // savePath = FileUtil.saveBitmap(bm);sczimage.setImageBitmap(bm);裁剪圖片
private void crop(file filePhoto) { // cropImagePath = file.getAbsolutePath();Intent intent = new Intent("com.android.camera.action.CROP");intent.setDataAndType(getImageContentUri(filePhoto), "image/*");intent.putExtra("crop", "true");intent.putExtra("aspectX", 300);intent.putExtra("aspectY", 300);intent.putExtra("outputX", 300);intent.putExtra("outputY", 300);intent.putExtra("scale", true);intent.putExtra("return-data", false);intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(filePhoto));intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());intent.putExtra("noFaceDetection", true);startActivityForResult(intent, RESULT_REQUEST_CODE);}3、解決三星手機(jī)拍照屏幕旋轉(zhuǎn)問題
在activity下面添加
<activity android:name=".activitys.SfzShiBieActivity"
? ? android:configChanges="keyboardHidden|orientation|screenSize"></activity>
?
?
或者
?
解決辦法2:
在Application的onCreat()方法中添加以下代碼:
// android 7.0系統(tǒng)解決拍照的問題StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();StrictMode.setVmPolicy(builder.build());builder.detectFileUriExposure();?
判斷相機(jī)
CameraManager manager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE); String[] cameraIds = new String[0]; try {cameraIds = manager.getCameraIdList(); } catch (CameraAccessException e) {e.printStackTrace(); } if (cameraIds != null && cameraIds.length > 0) {}else {showMyToast("請接入攝像頭!"); }?
總結(jié)
以上是生活随笔為你收集整理的Android 7.0 获取相机拍照图片,适配三星手机拍照,解决三星手机拍照屏幕旋转,判断设备是否有摄像头的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: blockchain_eth客户端安装
- 下一篇: Android 实时数据库工具Datab