GitHub地址:https://github.com/crazycodeboy/TakePhoto
一、配置
(1)在module build.gradle中添加
implementation 'com.jph.takephoto:takephoto_library:4.0.3'
如果点击sync后这行报错,则点击这个图标即可
(2)权限
AndroidManifest.xml中
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission> <uses-permission android:name="android.permission.INTERNET"></uses-permission> <uses-permission android:name="android.permission.CAMERA"></uses-permission>
二、实现步骤
(1)继承TakePhotoActivity
(2)重写takeSuccess,takeFail,takeCancel方法
(3)设置动态权限,适配6.0以上设备
三、代码实现
activity_main 简单的两个按钮和一个图片显示:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout 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" android:orientation="vertical" tools:context=".MainActivity"> <Button android:id="@+id/btnPhoto1" android:layout_width="match_parent" android:layout_heig