如何防止Android应用的自动备份? [英] How to prevent auto-backup of an Android app?
问题描述
我在某些设备上面临非常奇怪的情况(Nexus 5x与Android 7):当我清理数据并卸载它,然后用Studio安装时,该应用程序不是单元化的,但它使用的是1月24日的数据!我尝试使用平板电脑进行相同的操作,但应用程序没有数据。
我多次重复此过程,我清理了我的项目,重建了多次,它总是从第24个月的第一个数据开始(包括数据库和共享的首选项)。
我甚至尝试过adb shell并运行以清理数据:
bullhead:/data/data/lelisoft.com.lelimath.debug $ ls -l databases /
总计232
-rw-rw- --- 1 u0_a259 u0_a259 98304 2017-02-05 11:03 lelimath.sqlite
-rw ------- 1 u0_a259 u0_a259 16928 2017-02-05 11:03 lelimath.sqlite-journal
我删除了它们,应用程序似乎是空的 - 直到我删除它并再次安装 - 1月24日又回来了。 / p>
这是一个如何开始的日志:
$ adb shell am start -nlelisoft.com.lelimath.debug / lelisoft.com.lelimath.activities.DashboardActivity-a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
等待应用来到网上:lelisoft.com.lelimath.debug | lelisoft.com.lelimath.debug.test
I / InstantRun:即时运行运行时启动。 Android软件包是lelisoft.com.lelimath.debug,真正的应用程序类是lelisoft.com.lelimath.helpers.LeliMathApp。
D / lclhLeliMathApp:onCreate()
D / lclhBalanceHelper:当前积分余额:234
这是一个数据库的位置,来自调试器:
/ data / user / 0 / lelisoft .com.lelimath.debug / databases / lelimath.sqlite
Gradle:
android {
signingConfigs {
}
compileSdkVersion 24
buildToolsVersion23.0.3
defaultConfig {
applicationIdlelisoft.com.lelimath
resValue'string','app_name','LeliMath'
minSdkVersion 16
targetSdkVersion 24
versionCode 300
versionName'3.0.0'
resValuestring,app_build_number,getDate();
resValuestring,app_version,versionName;
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}
debug {
applicationIdSuffix.debug
resValue'tring','app_name','LeliMath DEV'
}
}
清单部分:
< application
android:name =。helpers.LeliMathApp
android:allowBackup =true
android:fullBackupContent =true
android:icon = @ mipmap / ic_launcher
android:label =@ string / app_name
android:theme =@ style / AppTheme
tools:ignore =GoogleAppIndexingWarning>
我不希望工厂重置我的手机以摆脱这些数据。我不认为这个数据在我的构建中。我没有添加它们,平板电脑上的应用程序在安装时是空的。
自从Android 6.0(第23版)开始, Android推出了一项名为自动备份应用的新功能。它的作用是,它将应用程序的某些文件备份到用户的Google驱动器。它更新的文件列表包括:
- 共享首选项文件
- 返回的目录中的文件
getFilesDir()
-
getDatabasePath(String)返回的目录中的文件
- 使用
getDir(String,int)创建的目录中的文件
- 外部存储上的文件在
返回的目录中getExternalFilesDir(String)
现在这行在 manifest.xml
负责:
android:allowBackup = true
如果您想要禁用备份,是否应该选择将值设置为 false
。
此外,备份的数据是24小时间隔,Android使用 JobScheduler 用于此目的的API,这意味着用户没有控制权l在传输数据的过程中。
此外,自动备份的空间限制为 25
MB ,并且不计入用户的空间配额。
此外,您可以设置为< include>
和< exclude>
某些类型的数据正在上传,例如您可能不需要保存用户的机密数据,所以它也很灵活,更多信息可从以下网址获取: Android应用的自动备份(Google Dev开发100天)
I face very weird situation on certain device (Nexus 5x with Android 7): when I clean its data and uninstall it, then install it with Studio, the app is not unitialized but it uses data from 24th january! I tried the same procedure with a tablet and the app has no data.
I have repeated this procedure many times, I cleaned my project, rebuilt it multiple times and it always starts with 24th january data (both database and shared prefs).
I even tried adb shell and run as to clean up data:
bullhead:/data/data/lelisoft.com.lelimath.debug $ ls -l databases/
total 232
-rw-rw---- 1 u0_a259 u0_a259 98304 2017-02-05 11:03 lelimath.sqlite
-rw------- 1 u0_a259 u0_a259 16928 2017-02-05 11:03 lelimath.sqlite-journal
I deleted them and the app seemed empty - until I deleted it and installed again - 24th january was back.
This is a log how it starts:
$ adb shell am start -n "lelisoft.com.lelimath.debug/lelisoft.com.lelimath.activities.DashboardActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: lelisoft.com.lelimath.debug | lelisoft.com.lelimath.debug.test
I/InstantRun: Instant Run Runtime started. Android package is lelisoft.com.lelimath.debug, real application class is lelisoft.com.lelimath.helpers.LeliMathApp.
D/l.c.l.h.LeliMathApp: onCreate()
D/l.c.l.h.BalanceHelper: Current points balance: 234
This is a location of a database, got from a debugger:
/data/user/0/lelisoft.com.lelimath.debug/databases/lelimath.sqlite
Gradle:
android {
signingConfigs {
}
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "lelisoft.com.lelimath"
resValue 'string', 'app_name', 'LeliMath'
minSdkVersion 16
targetSdkVersion 24
versionCode 300
versionName '3.0.0'
resValue "string", "app_build_number", getDate();
resValue "string", "app_version", versionName;
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
applicationIdSuffix ".debug"
resValue 'string', 'app_name', 'LeliMath DEV'
}
}
Manifest portion:
<application
android:name=".helpers.LeliMathApp"
android:allowBackup="true"
android:fullBackupContent="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
I do not want o factory reset my phone to get rid off this data. I do not think that this data is in my build. I have not added them and the app in the tablet was empty when installed.
Since Android 6.0 (v 23) onward, Android introduced a new feature called Auto-backup for apps . What this does is, it performs a backup of certain files of an application to a user's Google drive. The list of files it updates include:
- Shared preferences files
- Files in the directory returned by
getFilesDir()
- Files in the directory returned by
getDatabasePath(String)
- Files in directories created with
getDir(String, int)
- Files on external storage in the directory returned by
getExternalFilesDir(String)
Now this line in the manifest.xml
is responsible for it :
android:allowBackup="true"
If you prefer to disable the backup, should you choose to set the value to false
.
Furthermore, the data backed up is in a 24 hour interval and Android uses the JobScheduler API for this purpose, so which means a user has no control over the process of data being transferred.
Also, the space for auto-backups is limited to 25
MB , and which is not counted against the user's space quota.
Also, you can set to <include>
and <exclude>
certain type of data being uploaded, for instance you may not need to save a user confidential data, so it is flexible for that as well, more info on that is available at : Android Auto Backup for Apps (100 Days of Google Dev)
这篇关于如何防止Android应用的自动备份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!