Android三行代码快速拍照获取图片路径从相册选择图片
程序员文章站
2022-04-19 22:05:22
第一步Android studio打开build.gradle加入implementation 'com.jph.takephoto:takephoto_library:4.0.3'第二步,加入PhotoPickerActivity,不要忘了在Mainfest里面注册第三步,type=1是拍照、type=2是从相册选择Intent intent=new Intent(instance, PhotoPickerActivity.class);intent.putExtra("type",...
第一步Android studio打开build.gradle加入
implementation 'com.jph.takephoto:takephoto_library:4.0.3'
第二步,加入PhotoPickerActivity,不要忘了在Mainfest里面注册
第三步,type=1是拍照、type=2是从相册选择
Intent intent=new Intent(instance, PhotoPickerActivity.class);
intent.putExtra("type",1);
startActivityForResult(intent);
第四步,重写onActivityResult,这里的path就是文件路径,可以用Glide加载,可以上传到服务器
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == 1) {
String path = data.getStringExtra("path");
if (!TextUtils.isEmpty(path)) {
// uploadImage(path);
//Glide.with(instance).load(path).into(iv_touxiang);
}
}
}
获取PhotoPickerActivity点击 https://download.csdn.net/download/u013778491/12739788
本文地址:https://blog.csdn.net/u013778491/article/details/108171723