Implement backup mechanism for android-8 devices
This commit is contained in:
parent
13b7ec1f89
commit
986145eb4a
4 changed files with 42 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="net.osmand.plus" android:installLocation="auto" android:versionName="0.6.6" android:versionCode="35">
|
package="net.osmand.plus" android:installLocation="auto" android:versionName="0.6.6" android:versionCode="35">
|
||||||
|
<meta-data android:name="com.google.android.backup.api_key"
|
||||||
|
android:value="AEdPqrEAAAAIqF3tNGT66etVBn_vgzpfAY1wmIzKV1Ss6Ku-2A" />
|
||||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||||
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
android:debuggable="true" android:name=".activities.OsmandApplication" android:description="@string/app_description">
|
||||||
<activity android:name=".activities.MainMenuActivity"
|
<activity android:name=".activities.MainMenuActivity"
|
||||||
|
@ -55,7 +57,7 @@
|
||||||
<!-- comment change build properties for release & set targetSdkVersion="7", build and reverse changes-->
|
<!-- comment change build properties for release & set targetSdkVersion="7", build and reverse changes-->
|
||||||
<!-- <uses-sdk android:minSdkVersion="3"/> -->
|
<!-- <uses-sdk android:minSdkVersion="3"/> -->
|
||||||
<!-- uncomment it to allow different screen supports (large/small)-->
|
<!-- uncomment it to allow different screen supports (large/small)-->
|
||||||
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
|
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="7"/>
|
||||||
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
|
||||||
|
|
|
@ -14,6 +14,7 @@ import android.database.sqlite.SQLiteOpenHelper;
|
||||||
public class FavouritesDbHelper extends SQLiteOpenHelper {
|
public class FavouritesDbHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 1;
|
private static final int DATABASE_VERSION = 1;
|
||||||
|
public static final String FAVOURITE_DB_NAME = "favourite"; //$NON-NLS-1$
|
||||||
private static final String FAVOURITE_TABLE_NAME = "favourite"; //$NON-NLS-1$
|
private static final String FAVOURITE_TABLE_NAME = "favourite"; //$NON-NLS-1$
|
||||||
private static final String FAVOURITE_COL_NAME = "name"; //$NON-NLS-1$
|
private static final String FAVOURITE_COL_NAME = "name"; //$NON-NLS-1$
|
||||||
private static final String FAVOURITE_COL_LAT = "latitude"; //$NON-NLS-1$
|
private static final String FAVOURITE_COL_LAT = "latitude"; //$NON-NLS-1$
|
||||||
|
@ -26,7 +27,7 @@ public class FavouritesDbHelper extends SQLiteOpenHelper {
|
||||||
private Map<String, FavouritePoint> favoritePoints = null;
|
private Map<String, FavouritePoint> favoritePoints = null;
|
||||||
|
|
||||||
public FavouritesDbHelper(Context context) {
|
public FavouritesDbHelper(Context context) {
|
||||||
super(context, FAVOURITE_TABLE_NAME, null, DATABASE_VERSION);
|
super(context, FAVOURITE_DB_NAME, null, DATABASE_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<FavouritePoint> getFavoritePointsFromGPXFile() {
|
public List<FavouritePoint> getFavoritePointsFromGPXFile() {
|
||||||
|
|
28
OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java
Normal file
28
OsmAnd/src/net/osmand/plus/OsmandBackupAgent.java
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
package net.osmand.plus;
|
||||||
|
|
||||||
|
import net.osmand.plus.activities.ApplicationMode;
|
||||||
|
import android.app.backup.BackupAgentHelper;
|
||||||
|
import android.app.backup.FileBackupHelper;
|
||||||
|
import android.app.backup.SharedPreferencesBackupHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Requires android API from android-8
|
||||||
|
*/
|
||||||
|
public class OsmandBackupAgent extends BackupAgentHelper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
String[] prefs = new String[ApplicationMode.values().length + 1];
|
||||||
|
prefs[0] = OsmandSettings.getSharedPreferencesName(null);
|
||||||
|
int i = 1;
|
||||||
|
for (ApplicationMode m : ApplicationMode.values()) {
|
||||||
|
prefs[i++] = OsmandSettings.getSharedPreferencesName(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, prefs);
|
||||||
|
addHelper("osmand.settings", helper);
|
||||||
|
|
||||||
|
FileBackupHelper fileBackupHelper = new FileBackupHelper(this, FavouritesDbHelper.FAVOURITE_DB_NAME);
|
||||||
|
addHelper("osmand.favorites", fileBackupHelper);
|
||||||
|
}
|
||||||
|
}
|
|
@ -85,8 +85,16 @@ public class OsmandSettings {
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getSharedPreferencesName(ApplicationMode mode){
|
||||||
|
if(mode == null){
|
||||||
|
return SHARED_PREFERENCES_NAME;
|
||||||
|
} else {
|
||||||
|
return SHARED_PREFERENCES_NAME + "." + mode.name().toLowerCase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private SharedPreferences getProfilePreferences(ApplicationMode mode){
|
private SharedPreferences getProfilePreferences(ApplicationMode mode){
|
||||||
return ctx.getSharedPreferences(SHARED_PREFERENCES_NAME + "." + mode.name().toLowerCase(), Context.MODE_WORLD_READABLE);
|
return ctx.getSharedPreferences(getSharedPreferencesName(mode), Context.MODE_WORLD_READABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this value string is synchronized with settings_pref.xml preference name
|
// this value string is synchronized with settings_pref.xml preference name
|
||||||
|
|
Loading…
Reference in a new issue