Add BackupManager support
This commit is contained in:
parent
3a5e506c6c
commit
1bac719961
@ -27,7 +27,8 @@ THE SOFTWARE.
|
||||
android:installLocation="auto">
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name">
|
||||
android:label="@string/app_name"
|
||||
android:backupAgent="PreferencesBackupAgent">
|
||||
<activity
|
||||
android:name="LaunchActivity"
|
||||
android:theme="@style/NoBackground">
|
||||
@ -94,6 +95,9 @@ THE SOFTWARE.
|
||||
</intent-filter>
|
||||
</service>
|
||||
<activity android:name="PreferencesActivity" />
|
||||
<meta-data
|
||||
android:name="com.google.android.backup.api_key"
|
||||
android:value="AEdPqrEAAAAIH6Xcxa4hn6sHN1m4jMpi4MFFFMP5sv3XhFuWeA" />
|
||||
</application>
|
||||
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="10" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
@ -24,6 +24,7 @@ package org.kreed.vanilla;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentResolver;
|
||||
@ -35,6 +36,7 @@ import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.IBinder;
|
||||
@ -414,6 +416,9 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
} else if ("headset_play".equals(key)) {
|
||||
mHeadsetPlay = settings.getBoolean(key, false);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
|
||||
new BackupManager(this).dataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
|
41
src/org/kreed/vanilla/PreferencesBackupAgent.java
Normal file
41
src/org/kreed/vanilla/PreferencesBackupAgent.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2011 Christopher Eby <kreed@kreed.org>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package org.kreed.vanilla;
|
||||
|
||||
import android.app.backup.BackupAgentHelper;
|
||||
import android.app.backup.SharedPreferencesBackupHelper;
|
||||
|
||||
/**
|
||||
* Saves application preferences to the backup manager.
|
||||
*/
|
||||
public class PreferencesBackupAgent extends BackupAgentHelper {
|
||||
private static final String BACKUP_KEY = "prefs";
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
// This is the preference name used by PreferenceManager.getDefaultSharedPreferences
|
||||
String prefs = getPackageName() + "_preferences";
|
||||
addHelper(BACKUP_KEY, new SharedPreferencesBackupHelper(this, prefs));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user