Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
futurae-public
futurae-android-sdk
Commits
c1cc1207
Commit
c1cc1207
authored
Oct 05, 2021
by
dimitrisCBR
Committed by
Yorgos Galyfos
Oct 05, 2021
Browse files
Allow for host app data to be backed up
parent
71f696ea
Changes
6
Hide whitespace changes
Inline
Side-by-side
FuturaeDemo/app/build.gradle
View file @
c1cc1207
apply
plugin:
'com.android.application'
apply
plugin:
'kotlin-android'
android
{
compileSdkVersion
29
...
...
@@ -6,9 +7,9 @@ android {
defaultConfig
{
applicationId
"com.futurae.futuraedemo"
minSdkVersion
1
6
minSdkVersion
2
1
targetSdkVersion
29
versionCode
5
versionCode
6
versionName
"1.0.0"
resConfigs
"en"
,
"el"
testInstrumentationRunner
'androidx.test.runner.AndroidJUnitRunner'
...
...
@@ -46,7 +47,10 @@ repositories {
dependencies
{
implementation
fileTree
(
include:
[
'*.jar'
],
dir:
'libs'
)
implementation
'androidx.appcompat:appcompat:1.2.0'
implementation
"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation
"androidx.core:core-ktx:1.6.0"
implementation
'androidx.appcompat:appcompat:1.3.1'
implementation
'com.google.android.gms:play-services-vision:20.1.3'
implementation
'com.jakewharton:butterknife:10.2.3'
annotationProcessor
'com.jakewharton:butterknife-compiler:10.2.3'
...
...
@@ -57,7 +61,7 @@ dependencies {
implementation
'com.google.firebase:firebase-core:18.0.3'
implementation
'com.google.firebase:firebase-messaging:21.1.0'
implementation
(
'com.futurae.sdk:futuraekit:1.3.0'
)
//
implementation('com.futurae.sdk:futuraekit:1.3.0')
// Use these if you are NOT using Maven
// implementation 'com.squareup.retrofit2:retrofit:2.4.0'
...
...
@@ -67,7 +71,7 @@ dependencies {
// implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
// implementation 'com.github.nisrulz:easydeviceinfo-base:2.4.1'
// implementation 'com.google.code.gson:gson:2.8.6'
//
implementation files('
src/main/libs
/futuraekit.aar')
implementation
files
(
'
../..
/futuraekit.aar'
)
}
...
...
FuturaeDemo/app/src/main/AndroidManifest.xml
View file @
c1cc1207
...
...
@@ -15,7 +15,7 @@
<application
tools:replace=
"android:allowBackup"
android:allowBackup=
"true"
android:backupAgent=
".
Demo
BackupAgent"
android:backupAgent=
".
Custom
BackupAgent"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
android:name=
"com.futurae.futuraedemo.AppMain"
...
...
FuturaeDemo/app/src/main/java/com/futurae/futuraedemo/CustomBackupAgent.kt
0 → 100644
View file @
c1cc1207
package
com.futurae.futuraedemo
import
android.app.backup.BackupAgent
import
android.app.backup.BackupDataInput
import
android.app.backup.BackupDataOutput
import
android.os.ParcelFileDescriptor
import
android.util.Log
import
java.io.*
import
kotlin.random.Random
class
CustomBackupAgent
:
BackupAgent
()
{
private
val
TAG
=
CustomBackupAgent
::
class
.
simpleName
private
val
PREFS_BACKUP_KEY
=
"prefs_shared_prefs_backup_key"
override
fun
onBackup
(
oldState
:
ParcelFileDescriptor
?,
data
:
BackupDataOutput
,
newState
:
ParcelFileDescriptor
?)
{
try
{
//call SDK's backup agent
com
.
futurae
.
sdk
.
BackupAgent
.
onBackupAccounts
(
this
,
oldState
,
data
,
newState
)
//back up your own data
val
sp
=
getSharedPreferences
(
PREFS_NAME
,
MODE_PRIVATE
)
val
randomInt
=
Random
.
nextInt
(
10
)
sp
.
edit
().
putInt
(
PREF_RANDOM_STRING
,
randomInt
).
apply
()
val
preferenceValue
=
randomInt
.
toString
()
Log
.
d
(
TAG
,
"Starting backup of the prefs configuration in $PREFS_BACKUP_KEY, store: $randomInt as $preferenceValue"
)
val
bufStream
=
ByteArrayOutputStream
()
val
outWriter
=
DataOutputStream
(
bufStream
)
outWriter
.
writeUTF
(
preferenceValue
)
val
buffer
=
bufStream
.
toByteArray
()
val
len
=
buffer
.
size
data
.
writeEntityHeader
(
PREFS_BACKUP_KEY
,
len
)
data
.
writeEntityData
(
buffer
,
len
)
}
catch
(
e
:
IOException
)
{
Log
.
e
(
TAG
,
e
.
message
)
throw
e
}
}
override
fun
onRestore
(
data
:
BackupDataInput
,
appVersionCode
:
Int
,
newState
:
ParcelFileDescriptor
?)
{
while
(
data
.
readNextHeader
())
{
//if it's your backup key, proceed with restoring backed-up values
if
(
PREFS_BACKUP_KEY
==
data
.
key
)
{
try
{
val
dataSize
=
data
.
dataSize
val
dataBuf
=
ByteArray
(
dataSize
)
data
.
readEntityData
(
dataBuf
,
0
,
dataSize
)
val
baStream
=
ByteArrayInputStream
(
dataBuf
)
val
`in`
=
DataInputStream
(
baStream
)
val
storedValue
=
`in`
.
readUTF
()
if
(
storedValue
.
isBlank
())
{
return
}
Log
.
d
(
TAG
,
"onRestore: Prefs restore from the backup completed. Value: ${storedValue}, calling SDK backup agent"
)
val
sp
=
getSharedPreferences
(
PREFS_NAME
,
MODE_PRIVATE
)
sp
.
edit
().
putInt
(
PREF_RANDOM_STRING
,
storedValue
.
toInt
()).
apply
()
}
catch
(
e
:
IOException
)
{
Log
.
e
(
TAG
,
e
.
message
)
throw
e
}
catch
(
e
:
Exception
)
{
Log
.
d
(
TAG
,
e
.
message
)
}
}
else
{
com
.
futurae
.
sdk
.
BackupAgent
.
onRestoreAccountsData
(
this
,
data
)
}
}
}
companion
object
{
const
val
PREFS_NAME
=
"PREFS_NAME_CUSTOM"
const
val
PREF_RANDOM_STRING
=
"PREF_RANDOM_STRING"
}
}
\ No newline at end of file
FuturaeDemo/app/src/main/java/com/futurae/futuraedemo/DemoBackupAgent.java
deleted
100644 → 0
View file @
71f696ea
package
com.futurae.futuraedemo
;
import
android.app.backup.BackupDataInput
;
import
android.app.backup.BackupDataOutput
;
import
android.os.ParcelFileDescriptor
;
import
android.util.Log
;
import
com.futurae.sdk.BackupAgent
;
import
java.io.IOException
;
public
class
DemoBackupAgent
extends
android
.
app
.
backup
.
BackupAgent
{
private
static
final
String
TAG
=
DemoBackupAgent
.
class
.
getSimpleName
();
@Override
public
void
onBackup
(
ParcelFileDescriptor
oldState
,
BackupDataOutput
data
,
ParcelFileDescriptor
newState
)
{
try
{
BackupAgent
.
onBackupAccounts
(
this
,
oldState
,
data
,
newState
);
}
catch
(
IOException
e
)
{
Log
.
e
(
TAG
,
e
.
getMessage
(),
e
);
}
}
@Override
public
void
onRestore
(
BackupDataInput
data
,
int
appVersionCode
,
ParcelFileDescriptor
newState
)
{
try
{
BackupAgent
.
onRestoreAccounts
(
this
,
data
,
appVersionCode
,
newState
);
}
catch
(
IOException
e
)
{
Log
.
e
(
TAG
,
e
.
getMessage
(),
e
);
}
}
}
\ No newline at end of file
FuturaeDemo/build.gradle
View file @
c1cc1207
buildscript
{
ext
.
kotlin_version
=
'1.5.0'
repositories
{
google
()
jcenter
()
mavenCentral
()
}
dependencies
{
classpath
'com.android.tools.build:gradle:4.0.0'
classpath
'com.google.gms:google-services:4.2.0'
classpath
'com.google.gms:google-services:4.3.10'
classpath
"org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects
{
repositories
{
google
()
jcenter
()
mavenCentral
()
}
}
...
...
futuraekit.aar
View file @
c1cc1207
No preview for this file type
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment