Android 备份\u数据:在第X行跳过\u填充失败
我正在使用Google备份API进行SharedReference,如下所述: 使用bmgr时,如下所述: 我确实获得了onRestore和onBackup方法的日志消息,但在onRestore中,我得到了这一行:Android 备份\u数据:在第X行跳过\u填充失败,android,backup,Android,Backup,我正在使用Google备份API进行SharedReference,如下所述: 使用bmgr时,如下所述: 我确实获得了onRestore和onBackup方法的日志消息,但在onRestore中,我得到了这一行: 06-06 11:24:16.546: D/backup_data(24615): SKIP_PADDING FAILED at line 332 唯一的参考资料如下: 并且不读取任何输入 我的助手类: public class NoteBackupAgent extends
06-06 11:24:16.546: D/backup_data(24615): SKIP_PADDING FAILED at line 332
唯一的参考资料如下:
并且不读取任何输入
我的助手类:
public class NoteBackupAgent extends BackupAgentHelper {
public static final Object[] DATA_LOCK = new Object[0];
private static final String PREFS_BACKUP_KEY = Const.ENTRY_PREFS;
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
Log.d(toString(), "########### onBackup() " + oldState.getStatSize());
synchronized (DATA_LOCK) {
super.onBackup(oldState, data, newState);
}
}
@Override
public void onCreate() {
SharedPreferencesBackupHelper preferencesHelper = new SharedPreferencesBackupHelper(this,
getPackageName() + "_preferences");
Toast.makeText(getApplicationContext(), "onCreate", Toast.LENGTH_LONG).show();
addHelper(PREFS_BACKUP_KEY, preferencesHelper);
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode, ParcelFileDescriptor newState)
throws IOException {
synchronized (DATA_LOCK) {
//super.onRestore(data, appVersionCode, newState);
// There should be only one entity, but the safest
// way to consume it is using a while loop
StringBuilder total = new StringBuilder();
while (data.readNextHeader()) {
String key = data.getKey();
int dataSize = data.getDataSize();
// If the key is ours (for saving top score). Note this key was used when
// we wrote the backup entity header
if (PREFS_BACKUP_KEY.equals(key)) {
// Create an input stream for the BackupDataInput
byte[] dataBuf = new byte[dataSize];
data.readEntityData(dataBuf, 0, dataSize);
ByteArrayInputStream baStream = new ByteArrayInputStream(dataBuf);
DataInputStream in = new DataInputStream(baStream);
BufferedReader r = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = r.readLine()) != null) {
total.append(line);
}
Log.d(toString(), "########## data " + total);
} else {
data.skipEntityData();
}
}
Log.d(toString(), "########## onRestore()" + total.toString());
}
}
}
在我们的例子中,解决方案是防止对存储在共享首选项中的值强制执行Base64编码。 正如您输入@Demonick时指出的,是错误的原因,BackUpdateAreader::skip_padding正在对填充使用Base32编码 结论是:
禁止使用Base64.encodeToStringinput、Base64.NO_填充来写入共享首选项。否,没有其他信息。您在某个地方找到了更多关于此的信息吗?还有其他选择吗?@CarloLópezScutaro没有找到solution@Demonick您使用的是Base64编码吗?我想这可能是我失败的原因。当我切换到vanila SharedReferences时,一切都是开箱即用的。更详细地说:我们对SharedReferences的加密是使用Base64.encodeToStringinput、Base64.NO_PADDING、Base64.NO_WRAP设置值的编码,这似乎破坏了备份-agent@carlosavoy嗨,我对这一切都很陌生。如何检查是否使用Base64编码?我如何切换到香草共享参考?感谢您提供的任何帮助:-很好的发现,将有助于今后的参考。