我正在开发一个我正在研究 Google Backup API 的 android 应用程序,我阅读了本教程 http://www.edumobile.org/android/android-development/backup-manager/
并试图实现它,但它一直在崩溃
Logcat 是
07-31 13:39:35.797: E/AndroidRuntime(18279): FATAL EXCEPTION: main
07-31 13:39:35.797: E/AndroidRuntime(18279): java.lang.IllegalStateException: Could not execute method of the activity
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.view.View$1.onClick(View.java:2072)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.view.View.performClick(View.java:2408)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.view.View$PerformClick.run(View.java:8816)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.os.Handler.handleCallback(Handler.java:587)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.os.Handler.dispatchMessage(Handler.java:92)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.os.Looper.loop(Looper.java:123)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.app.ActivityThread.main(ActivityThread.java:4633)
07-31 13:39:35.797: E/AndroidRuntime(18279): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 13:39:35.797: E/AndroidRuntime(18279): at java.lang.reflect.Method.invoke(Method.java:521)
07-31 13:39:35.797: E/AndroidRuntime(18279): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
07-31 13:39:35.797: E/AndroidRuntime(18279): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
07-31 13:39:35.797: E/AndroidRuntime(18279): at dalvik.system.NativeStart.main(Native Method)
07-31 13:39:35.797: E/AndroidRuntime(18279): Caused by: java.lang.reflect.InvocationTargetException
07-31 13:39:35.797: E/AndroidRuntime(18279): at com.pref.BackupManagerExample.onRestoreButtonClick(BackupManagerExample.java:164)
07-31 13:39:35.797: E/AndroidRuntime(18279): at java.lang.reflect.Method.invokeNative(Native Method)
07-31 13:39:35.797: E/AndroidRuntime(18279): at java.lang.reflect.Method.invoke(Method.java:521)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.view.View$1.onClick(View.java:2067)
07-31 13:39:35.797: E/AndroidRuntime(18279): ... 11 more
07-31 13:39:35.797: E/AndroidRuntime(18279): Caused by: java.lang.SecurityException: getCurrentTransport: Neither user 10066 nor current process has android.permission.BACKUP.
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.os.Parcel.readException(Parcel.java:1247)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.os.Parcel.readException(Parcel.java:1235)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.app.backup.IBackupManager$Stub$Proxy.getCurrentTransport(IBackupManager.java:444)
07-31 13:39:35.797: E/AndroidRuntime(18279): at android.app.backup.BackupManager.requestRestore(BackupManager.java:141)
07-31 13:39:35.797: E/AndroidRuntime(18279): ... 15 more
而清单是
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pref"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.BACKUP" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:backupAgent="com.pref.BackupManagerExample">
<activity android:name=".Preff" />
<activity
android:name=".PrefrencesActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIo8gaMLEy1sb1bVd6Cyqs5dxPAy8qvFzfILeLWB" />
<activity
android:name=".BackupManagerExample"
android:enabled="true"/>
</application>
</manifest>
错误在这里
Resotre.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
// TODO Auto-generated method stub
// 此行显示错误
mBackupManager.requestRestore(
new RestoreObserver() {
public void restoreFinished(int error) {
Log.v(TAG, "Restore finished, error = " + error);
populateUI();
}
}
);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
此错误的原因可能是什么?我怎样才能删除它?
编辑
不是这个,但我也使用了这个代码,
https://github.com/StylingAndroid/BackupRestore
只是为了看看备份 API 是如何工作的,这也给出了同样的错误。
07-31 18:10:33.226: E/AndroidRuntime(20664): Caused by: java.lang.SecurityException: getCurrentTransport: Neither user 10072 nor current process has android.permission.BACKUP.
从这里我读到
http://developer.android.com/guide/topics/data/backup.html
数据备份不保证在所有 Android 设备上都可用。但是,如果设备不提供备份传输,您的应用程序不会受到不利影响。
我使用的设备是三星 Galaxy Pop。