作者 liyan

添加拍照和打开相册工具类2

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.br_technology.securitytrain_master">
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
... ... @@ -7,6 +8,8 @@
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<application
android:name=".base.view.BaseApplication"
... ... @@ -38,6 +41,16 @@
android:name="notch.config"
android:value="portrait|landscape" />
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
<activity
android:name=".ui.login.AccountLoginActivity"
... ...
package com.br_technology.securitytrain_master.ui.mine.activity
import android.Manifest
import android.content.Intent
import android.view.View
import android.widget.Toast
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.ActivityEditPersonalInfoBinding
import com.br_technology.securitytrain_master.ext.initPermissions
import com.br_technology.securitytrain_master.ui.mine.viewmodel.EditPersonalInfoViewModel
import com.br_technology.securitytrain_master.util.PhotoUtils
import com.gyf.immersionbar.ImmersionBar
import com.wjx.android.wanandroidmvvm.base.view.BaseLifeCycleActivity
... ... @@ -51,7 +53,18 @@ class EditPersonalInfoActivity :
R.id.rl_up_load_image -> {
//上传和修改头像
initPermissions(Manifest.permission.CAMERA,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
onGranted = {
PhotoUtils.get().photoDialogShow(this,"",object : PhotoUtils.PhotoCallBack{
override fun onSuccessListener(imagePath: String?) {
//上传照片到服务器
}
override fun onFailListener() {
//失败的回调
}
})
Toast.makeText(baseContext, "ccccc", Toast.LENGTH_SHORT).show()
},
onDenied = {
... ... @@ -62,4 +75,12 @@ class EditPersonalInfoActivity :
}
}
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK){
PhotoUtils.get().onActivityResult(this,requestCode,resultCode,data!!)
}
}
}
\ No newline at end of file
... ...
... ... @@ -30,8 +30,6 @@ import java.io.FileNotFoundException
* Description: 初见时你很迷人
*/
class PhotoUtils {
@Volatile
private var mInstance: PhotoUtils? = null
private val REQUEST_IMAGE_ALBUM = 0
private val REQUEST_IMAGE_CAMERA = 1
private val REQUEST_IMAGE_CUTTING = 2
... ... @@ -43,15 +41,17 @@ class PhotoUtils {
private var mCallBack: PhotoCallBack? = null
fun getInstance(): PhotoUtils? {
if (mInstance == null) {
synchronized(PhotoUtils::class.java) {
if (mInstance == null) {
mInstance = PhotoUtils()
companion object {
private var instance:PhotoUtils ? = null
get() {
if (field == null){
field = PhotoUtils()
}
return field
}
fun get(): PhotoUtils{
return instance!!
}
return mInstance
}
/**
... ...
<?xml version="1.0" encoding="utf-8"?>
<paths>
<!-- root-path 手机存储根目录 -->
<root-path
name="download"
path="" />
</paths>
\ No newline at end of file
... ...