android系统支持的图片格式,Android版本兼容(存储、http,相机、SparseArray、升级)...

版本兼容处理(后续我会一直迭代下去的,只要遇到了就更新,希望能帮到大家)

Android 11 存储规范

Android 10(API 29),在Android 10设备操作文件无效,临时解决方案为在AndroidManifest.xml中application标签添加以下属性:

注:如果你无法添加requestLegacyExternalStorage="true"属性,请查看你的targetSdkVersion,只有在28以上才有

android:allowBackup="true"

android:icon="@drawable/logo"

android:label="@string/app_name"

android:supportsRtl="true"

android:requestLegacyExternalStorage="true">

http请求支持

Android 9.0(API 27),如进行http请求,需AndroidManifest.xml中application标签添加以下属性:

android:allowBackup="true"

android:icon="@drawable/logo"

android:label="@string/app_name"

android:supportsRtl="true"

android:usesCleartextTraffic="true">

android:allowBackup="true"

android:icon="@drawable/logo"

android:label="@string/app_name"

android:supportsRtl="true"

android:networkSecurityConfig="@xml/net_config">

net_config.xml

Android7.0调用系统相机图片路径处理

1.首先你需要在你的res路径新建一个xml文件夹,并新建一个filepath.xml文件(命名可修改)

2.在你的filepath.xml里面添加存储设置

3.然后在manifest文件里面添加provide配置

android:name="androidx.core.content.FileProvider"

android:authorities="${applicationId}.provider"

android:exported="false"

android:grantUriPermissions="true">

android:name="android.support.FILE_PROVIDER_PATHS"

android:resource="@xml/file_paths" />

Android10关于SparseArray转json不支持的问题

建议使用map,不使用SparseArray

SparseArray> sparseArray = new SparseArray<>();

Map map = new HashMap<>();

Map> map1 = new HashMap<>();

map.put(100,"大爷");

sparseArray.put(1,map);

map1.put(2,map);

String mapJson = GsonUtil.beanToJSONString(map);

String map1Json = GsonUtil.beanToJSONString(map1);

String sparseJson = GsonUtil.beanToJSONString(sparseArray);

Log.i("sss",mapJson);

Log.i("sss",map1Json);

Log.i("sss",sparseJson);

以上三个值分别为:

mapJson:{"100":"大爷"}

map1Json:{"2":{"100":"大爷"}}

sparseJson:{}

Android9的升级适配

此处9之前版本intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);可生效,9含之后就只能addflag了,否则提示解析包异常

public static boolean install(Context context, File file) {

Log.i("install", "安装包路径为:" + file.getPath());

try {

if (context != null && file != null) {

Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

if (Build.VERSION.SDK_INT >= 24) {

Uri apkUri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".fileProvider", file);

intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);

intent.setDataAndType(apkUri, "application/vnd.android.package-archive");

} else {

intent.setDataAndType(Uri.fromFile(file), "application/vnd.android.package-archive");

}

context.startActivity(intent);

return true;

}

} catch (Exception e) {

e.printStackTrace();

}

return false;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值