Android P Camera2当SD卡被拔出来自动切换到内部存储
程序员文章站
2022-03-28 17:50:43
需求: Camera2 当拔出SD卡后,设备一直提示“无法访问SD卡”,体验不好修改方法:依据现有流程中的当内部存储空间不够时候,切换到SD的方案修改判断提示的函数为:packages/apps/SnapdragonCamera / src/com/android/camera/CameraActivity.java protected long updateStorageSpace() { synchronized (mStorageSpaceLock) {...
需求: Camera2 当拔出SD卡后,设备一直提示“无法访问SD卡”,体验不好
修改方法:依据现有流程中的当内部存储空间不够时候,切换到SD的方案修改
判断提示的函数为:packages/apps/SnapdragonCamera / src/com/android/camera/CameraActivity.java
protected long updateStorageSpace() {
synchronized (mStorageSpaceLock) {
mStorageSpaceBytes = Storage.getAvailableSpace();
if (Storage.switchSavePath()) {
mStorageSpaceBytes = Storage.getAvailableSpace();
mMainHandler.sendEmptyMessage(SWITCH_SAVE_PATH);
} **else if (Storage.switchInternalSavePath()) {
mStorageSpaceBytes = Storage.getAvailableSpace();
mMainHandler.sendEmptyMessage(SWITCH_INTERNAL_SAVE_PATH);
}**
return mStorageSpaceBytes;
}
}
其判断函数为:packages/apps/SnapdragonCamera / src/com/android/camera/Storage.java
public static boolean switchInternalSavePath() {
if (isSaveSDCard()
&& getInternalStorageAvailableSpace() > LOW_STORAGE_THRESHOLD_BYTES
&& getSDCardAvailableSpace() == UNKNOWN_SIZE) {
setSaveSDCard(false);
return true;
}
return false;
}
判断SD卡的状态后,然后就是切换SD卡的存储了
private class MainHandler extends Handler {
public MainHandler(Looper looper) {
super(looper);
}
@Override
public void handleMessage(Message msg) {
if (msg.what == HIDE_ACTION_BAR) {
removeMessages(HIDE_ACTION_BAR);
CameraActivity.this.setSystemBarsVisibility(false);
} else if ( msg.what == SWITCH_SAVE_PATH ) {
mCurrentModule.onSwitchSavePath();
} else if ( msg.what == SWITCH_INTERNAL_SAVE_PATH ) {
mCurrentModule.onSwitchInternalSavePath();
}
}
}
在查找器对应的实现函数接口mCurrentModule.onSwitchInternalSavePath()
packages/apps/SnapdragonCamera / src/com/android/camera/CaptureModule.java
@Override
public void onSwitchSavePath() {
mSettingsManager.setValue(SettingsManager.KEY_CAMERA_SAVEPATH, "1");
RotateTextToast.makeText(mActivity, R.string.on_switch_save_path_to_sdcard,
Toast.LENGTH_SHORT).show();
}
@Override
public void onSwitchInternalSavePath() {
mSettingsManager.setValue(SettingsManager.KEY_CAMERA_SAVEPATH, "0");
RotateTextToast.makeText(mActivity, R.string.on_switch_save_path_to_internal,
Toast.LENGTH_SHORT).show();
}
以上修改即可满足要求。
本文地址:https://blog.csdn.net/liuminx/article/details/107391690
上一篇: iOS KVC 简介
下一篇: 显示已经过时的警告