update
This commit is contained in:
@@ -257,6 +257,16 @@ public class IMLoginModel extends BaseModel {
|
||||
private String guardType = "";
|
||||
@SerializedName("need_bind")
|
||||
int needBind;
|
||||
@SerializedName("online")
|
||||
private String online ;
|
||||
|
||||
public String getOnline() {
|
||||
return online;
|
||||
}
|
||||
|
||||
public void setOnline(String online) {
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
public int getNeedBind() {
|
||||
return needBind;
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -101,10 +104,10 @@ public class ProcessImageUtil extends ProcessResultUtil {
|
||||
mAlumbResultCallback = new ActivityResultCallback() {
|
||||
@Override
|
||||
public void onSuccess(Intent intent) {
|
||||
if(mNeedCrop) {
|
||||
if (mNeedCrop) {
|
||||
crop(intent.getData());
|
||||
}else{
|
||||
mResultCallback.onSuccess(new File(intent.getData().toString()));
|
||||
} else {
|
||||
mResultCallback.onSuccess(new File(getFilePathForUri(mContext,intent.getData())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,6 +152,7 @@ public class ProcessImageUtil extends ProcessResultUtil {
|
||||
public void getImageByAlumb() {
|
||||
getImageByAlumb(true);
|
||||
}
|
||||
|
||||
public void getImageByAlumb(boolean needCrop) {
|
||||
mNeedCrop = needCrop;
|
||||
requestPermissions(mAlumbPermissions, mAlumbPermissionCallback);
|
||||
@@ -243,6 +247,65 @@ public class ProcessImageUtil extends ProcessResultUtil {
|
||||
mResultCallback = resultCallback;
|
||||
}
|
||||
|
||||
private static String getFilePathForUri(Context context, Uri uri) {
|
||||
String filePath = null;
|
||||
if (DocumentsContract.isDocumentUri(context, uri)) {
|
||||
// 如果是document类型的 uri, 则通过document id来进行处理
|
||||
String documentId = DocumentsContract.getDocumentId(uri);
|
||||
if (isMediaDocument(uri)) { // MediaProvider
|
||||
// 使用':'分割
|
||||
String id = documentId.split(":")[1];
|
||||
String selection = MediaStore.Images.Media._ID + "=?";
|
||||
String[] selectionArgs = {id};
|
||||
filePath = getDataColumn(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection, selectionArgs);
|
||||
} else if (isDownloadsDocument(uri)) { // DownloadsProvider
|
||||
Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(documentId));
|
||||
filePath = getDataColumn(context, contentUri, null, null);
|
||||
}
|
||||
} else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
||||
// 如果是 content 类型的 Uri
|
||||
filePath = getDataColumn(context, uri, null, null);
|
||||
} else if ("file".equals(uri.getScheme())) {
|
||||
// 如果是 file 类型的 Uri,直接获取图片对应的路径
|
||||
filePath = uri.getPath();
|
||||
}
|
||||
return filePath;
|
||||
}
|
||||
|
||||
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
|
||||
String path = null;
|
||||
String[] projection = new String[]{MediaStore.Images.Media.DATA};
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
|
||||
if (cursor != null && cursor.moveToFirst()) {
|
||||
int columnIndex = cursor.getColumnIndexOrThrow(projection[0]);
|
||||
path = cursor.getString(columnIndex);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (cursor != null) {
|
||||
cursor.close();
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri the Uri to check
|
||||
* @return Whether the Uri authority is MediaProvider
|
||||
*/
|
||||
private static boolean isMediaDocument(Uri uri) {
|
||||
return "com.android.providers.media.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param uri the Uri to check
|
||||
* @return Whether the Uri authority is DownloadsProvider
|
||||
*/
|
||||
private static boolean isDownloadsDocument(Uri uri) {
|
||||
return "com.android.providers.downloads.documents".equals(uri.getAuthority());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void release() {
|
||||
super.release();
|
||||
|
||||
Reference in New Issue
Block a user