当前位置: 代码迷 >> 综合 >> Android 11版本适配 API调整
  详细解决方案

Android 11版本适配 API调整

热度:37   发布时间:2024-02-19 19:54:38.0

记录android 11版本的API调整:

1. SQLiteDatabase API变化:

 删除旧版本hide的接口: addCustomFunction(String name, int numArgs, CustomFunction function)

如果采用技术手段骗过编译器或者使用反射调用给接口,就会出现崩溃异常, Android 11版本修改后的替换接口有两个:

(1). 设置自定义标量函数: 

setCustomScalarFunction(@NonNull String functionName,
            @NonNull UnaryOperator<String> scalarFunction) throws SQLiteException

(2). 设置自定义聚合函数: 

setCustomAggregateFunction(@NonNull String functionName,
            @NonNull BinaryOperator<String> aggregateFunction) throws SQLiteException

注释:  Scalar 函数基于输入值,返回一个单一的值; Aggregate 函数计算从列中取得的值,返回一个单一的值;

(3)用法举例:

 android 11之前版本在数据操作的删除触发器使用了回调自定义接口:

db.execSQL("CREATE TRIGGER IF NOT EXISTS files_cleanup DELETE ON files " +"BEGIN " +"SELECT _OBJECT_REMOVED(old._id);" +"END");

老版本实现注册自定义回调接口: 

db.addCustomFunction("_OBJECT_REMOVED", 1, mObjectRemovedCallback);

升级到android 11版本后可改成自定义标量函数回调:  

db.setCustomScalarFunction("_OBJECT_REMOVED", mObjectRemovedOperator);

 

后续陆续更新.................


  相关解决方案