解决办法:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
}
android:usesCleartextTraffic="true"
参考:
https://blog.csdn.net/woyaochenggong774/article/details/80448698
原因:android权限的问题
修改方法:
net_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config xmlns:android="http://schemas.android.com/apk/res/android">
<base-config cleartextTrafficPermitted="true">
<trust-anchors>
<certificates src="system" overridePins="true" />
<certificates src="user" overridePins="true" />
</trust-anchors>
</base-config>
</network-security-config>
android:networkSecurityConfig="@xml/net_security_config"
https://developer.android.google.cn/training/articles/user-data-ids
采取谷歌推荐做法,自定义生成UUID:
@SuppressLint("ApplySharedPref")
public static String getDeviceId(Context context) {
SharedPreferences deviceIdSp = context.getApplicationContext()
.getSharedPreferences(DEVICE_ID_SP_NAME, Context.MODE_PRIVATE);
String deviceId = deviceIdSp.getString(DEVICE_ID_KEY, "");
if (TextUtils.isEmpty(deviceId)) {
deviceId = UUID.randomUUID().toString();
deviceIdSp.edit().putString(DEVICE_ID_KEY, deviceId).commit();
}
return deviceId;
}
解决办法:将手机系统升级到MIUI 11.0.4后问题解决。
参考资料:
https://blog.csdn.net/yehui928186846/article/details/101706238
https://developer.android.google.cn/reference/android/os/Environment.html#getExternalStorageDirectory()
This method was deprecated in API level 29.
To improve user privacy, direct access to shared/external storage devices is deprecated. When an app targets Build.VERSION_CODES.Q, the path returned from this method is no longer directly accessible to apps. Apps can continue to access content stored on shared/external storage by migrating to alternatives such as Context#getExternalFilesDir(String), MediaStore, or Intent#ACTION_OPEN_DOCUMENT.
参考资料:https://juejin.im/post/5d80ef726fb9a06aeb10f223
拍照必须使用file provider;
相册选取的图片不展示的问题:
解决方案:读取bitmap,将其压缩并存储在data/package_name/files 文件夹下,使用bitmapFactory.decodeFile加载bitmap展示在imageview上。
//获取图片Uri
private static Uri getImageContentUri(Context context, String path) {
Cursor cursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.Media._ID}, MediaStore.Images.Media.DATA + "=? ",
new String[]{path}, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
Uri baseUri = Uri.parse("content://media/external/images/media");
return Uri.withAppendedPath(baseUri, "" + id);
} else {
// 如果图片不在手机的共享图片数据库,就先把它插入。
if (new File(path).exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, path);
return context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
return null;
}
}
}
//读取bitmap,并压缩
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Uri imageUri = getImageContentUri(JDSendApp.getInstance(), srcFilePath);
ParcelFileDescriptor parcelFileDescriptor = context
.getApplicationContext()
.getContentResolver()
.openFileDescriptor(imageUri, "r");
BitmapFactory.decodeFileDescriptor(parcelFileDescriptor.getFileDescriptor(), null, options);
// 计算采样率
if (reqHeight == 0) {
options.inSampleSize = calculateInSampleSize(options, reqWidth);
} else {
options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
}
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
return BitmapFactory.decodeFileDescriptor(parcelFileDescriptor.getFileDescriptor(), null, options);