Methods Summary |
---|
public void | backupNow()Schedule an immediate backup attempt for all pending key/value updates. This
is primarily intended for transports to use when they detect a suitable
opportunity for doing a backup pass. If there are no pending updates to
be sent, no action will be taken. Even if some updates are pending, the
transport will still be asked to confirm via the usual requestBackupTime()
method.
Callers must hold the android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
sService.backupNow();
} catch (RemoteException e) {
Log.e(TAG, "backupNow() couldn't connect");
}
}
|
public android.app.backup.RestoreSession | beginRestoreSession()Begin the process of restoring data from backup. See the
{@link android.app.backup.RestoreSession} class for documentation on that process.
RestoreSession session = null;
checkServiceBinder();
if (sService != null) {
try {
// All packages, current transport
IRestoreSession binder = sService.beginRestoreSession(null, null);
if (binder != null) {
session = new RestoreSession(mContext, binder);
}
} catch (RemoteException e) {
Log.e(TAG, "beginRestoreSession() couldn't connect");
}
}
return session;
|
private static void | checkServiceBinder()
if (sService == null) {
sService = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
}
|
public void | dataChanged()Notifies the Android backup system that your application wishes to back up
new changes to its data. A backup operation using your application's
{@link android.app.backup.BackupAgent} subclass will be scheduled when you
call this method.
checkServiceBinder();
if (sService != null) {
try {
sService.dataChanged(mContext.getPackageName());
} catch (RemoteException e) {
Log.d(TAG, "dataChanged() couldn't connect");
}
}
|
public static void | dataChanged(java.lang.String packageName)Convenience method for callers who need to indicate that some other package
needs a backup pass. This can be useful in the case of groups of packages
that share a uid.
This method requires that the application hold the "android.permission.BACKUP"
permission if the package named in the argument does not run under the same uid
as the caller.
checkServiceBinder();
if (sService != null) {
try {
sService.dataChanged(packageName);
} catch (RemoteException e) {
Log.e(TAG, "dataChanged(pkg) couldn't connect");
}
}
|
public java.lang.String | getCurrentTransport()Identify the currently selected transport. Callers must hold the
android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
return sService.getCurrentTransport();
} catch (RemoteException e) {
Log.e(TAG, "getCurrentTransport() couldn't connect");
}
}
return null;
|
public boolean | isBackupEnabled()Report whether the backup mechanism is currently enabled.
Callers must hold the android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
return sService.isBackupEnabled();
} catch (RemoteException e) {
Log.e(TAG, "isBackupEnabled() couldn't connect");
}
}
return false;
|
public java.lang.String[] | listAllTransports()Request a list of all available backup transports' names. Callers must
hold the android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
return sService.listAllTransports();
} catch (RemoteException e) {
Log.e(TAG, "listAllTransports() couldn't connect");
}
}
return null;
|
public int | requestRestore(RestoreObserver observer)Restore the calling application from backup. The data will be restored from the
current backup dataset if the application has stored data there, or from
the dataset used during the last full device setup operation if the current
backup dataset has no matching data. If no backup data exists for this application
in either source, a nonzero value will be returned.
If this method returns zero (meaning success), the OS will attempt to retrieve
a backed-up dataset from the remote transport, instantiate the application's
backup agent, and pass the dataset to the agent's
{@link android.app.backup.BackupAgent#onRestore(BackupDataInput, int, android.os.ParcelFileDescriptor) onRestore()}
method.
int result = -1;
checkServiceBinder();
if (sService != null) {
RestoreSession session = null;
try {
IRestoreSession binder = sService.beginRestoreSession(mContext.getPackageName(),
null);
if (binder != null) {
session = new RestoreSession(mContext, binder);
result = session.restorePackage(mContext.getPackageName(), observer);
}
} catch (RemoteException e) {
Log.e(TAG, "restoreSelf() unable to contact service");
} finally {
if (session != null) {
session.endRestoreSession();
}
}
}
return result;
|
public java.lang.String | selectBackupTransport(java.lang.String transport)Specify the current backup transport. Callers must hold the
android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
return sService.selectBackupTransport(transport);
} catch (RemoteException e) {
Log.e(TAG, "selectBackupTransport() couldn't connect");
}
}
return null;
|
public void | setAutoRestore(boolean isEnabled)Enable/disable data restore at application install time. When enabled, app
installation will include an attempt to fetch the app's historical data from
the archival restore dataset (if any). When disabled, no such attempt will
be made.
Callers must hold the android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
sService.setAutoRestore(isEnabled);
} catch (RemoteException e) {
Log.e(TAG, "setAutoRestore() couldn't connect");
}
}
|
public void | setBackupEnabled(boolean isEnabled)Enable/disable the backup service entirely. When disabled, no backup
or restore operations will take place. Data-changed notifications will
still be observed and collected, however, so that changes made while the
mechanism was disabled will still be backed up properly if it is enabled
at some point in the future.
Callers must hold the android.permission.BACKUP permission to use this method.
checkServiceBinder();
if (sService != null) {
try {
sService.setBackupEnabled(isEnabled);
} catch (RemoteException e) {
Log.e(TAG, "setBackupEnabled() couldn't connect");
}
}
|