日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android 7.0 获取相机拍照图片,适配三星手机拍照,解决三星手机拍照屏幕旋转,判断设备是否有摄像头

發(fā)布時(shí)間:2023/12/10 Android 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。