利用android takephoto v4.1.0库实现拍照,相册选择
此处直接用takephoto开源的代码库,不用依赖的方式,下载地址:https://download.csdn.net/download/leansmall/13037835
一,布局如下:
<?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_height="wrap_content"
android:text="拍照" />
<Button
android:id="@+id/btnPhoto2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="从相册获取" />
<Button
android:id="@+id/btnUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="上传" />
<ImageView
android:id="@+id/ivPhoto"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
二,代码如下:
package com.leansmall.testphoto;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.ContextWrapper;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import com.bumptech.glide.Glide;
import org.devio.takephoto.app.TakePhoto;
import org.devio.takephoto.app.TakePhotoActivity;
import org.devio.takephoto.compress.CompressConfig;
import org.devio.takephoto.model.CropOptions;
import org.devio.takephoto.model.TResult;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends TakePhotoAct