一、 android34升级:
1、升级到安卓34(蓝牙、图片)
再蓝牙广播的地方加入Context.RECEIVER_EXPORTED
2、废弃了 BluetoothAdapter#enable() 和 BluetoothAdapter#disable(),需要修改
// 以前的蓝牙操作
BluetoothManager bluetoothManager = (BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
Log.i(TAG, "BluetoothAdapter isEnabled: " + bluetoothAdapter.isEnabled());
if (!bluetoothAdapter.isEnabled()) {
boolean enable = bluetoothAdapter.enable();
Log.i(TAG, "BluetoothAdapter enable result: " + enable);
}
// 现在需要这样
BluetoothManager bluetoothManager = (BluetoothManager) this.getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter bluetoothAdapter = bluetoothManager.getAdapter();
Log.i(TAG, "BluetoothAdapter isEnabled: " + bluetoothAdapter.isEnabled());
if (!bluetoothAdapter.isEnabled()) {
ActivityResultLauncher<Intent> register = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result == null) {
Log.i(TAG, "开启蓝牙失败:result 为 null");
return;
}
int resultCode = result.getResultCode();
if (resultCode != Activity.RESULT_OK) {
Log.i(TAG, "开启蓝牙失败:resultCode 为 " + resultCode);
return;
}
Log.i(TAG, "开启蓝牙成功:resultCode 为 " + resultCode);
}
});
Intent intent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
register.launch(intent);
}
图片-头像-拍照:
androidmainfest 增加权限: Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED,
代码中动态请求:
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED,
请求权限参考代码
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
&& (ContextCompat.checkSelfPermission(this, READ_MEDIA_IMAGES) == PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(this, READ_MEDIA_VIDEO) == PERMISSION_GRANTED)
) {
// Android 13及以上完整照片和视频访问权限
} else if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
ContextCompat.checkSelfPermission(this, READ_MEDIA_VISUAL_USER_SELECTED) == PERMISSION_GRANTED
) {
// Android 14及以上部分照片和视频访问权限
} else if (ContextCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) == PERMISSION_GRANTED) {
// Android 12及以下完整本地读写访问权限
} else {
// 无本地读写访问权限
}
======================================================================================
打aab包:
1、将项目中的\app\src\main\assets中的bin文件夹全部移动到base_assets文件夹
2、打包aab:build->Android App Bundle->选择签名,得到aab的包
===============================================
直接AS运行到手机上测试的:
1、需要将base_assets中的\base_assets\src\main\assets的bin文件,拷贝到\app\src\main\assets
2、移除base_assets文件夹
================================================
将aab转换为apks
1、将aab的包拷贝到AAB_TO_APK文件夹(名称默认为app-release.aab),
2、点击click.bat,出来小黑屏,等待apks的生成 (如果无响应的,重新下载bundletool-all-1.18.1的版本、检查jdk的版本)
下载链接:https://github.com/google/bundletool/releases
3、得到出来aa.apks,解压获得apk的文件包
4、安装到手机测试功能