1

I am developing an android application for which i was studying about Google Backup API , i read this tutorial http://www.edumobile.org/android/android-development/backup-manager/

and tried to implement it but it is crashing all the time

The Logcat is

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

and the menifest is

   <?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>

Ther Error is here

 Resotre.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    // TODO Auto-generated method stub

// This line shows the error

 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();
                    }
                }
            });

What could be the cause for this error ? And how can i remove it ?

Edit

Not olny this but i also used this code ,

https://github.com/StylingAndroid/BackupRestore

Just to see how backup API works and this also gave the same error .

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.

From here i read

http://developer.android.com/guide/topics/data/backup.html

Data backup is not guaranteed to be available on all Android-powered devices. However, your application is not adversely affected in the event that a device does not provide a backup transport.

The device i am using is a samsung galaxy pop.

HitOdessit
  • 7,198
  • 4
  • 36
  • 59
Avi Kumar
  • 4,403
  • 8
  • 36
  • 67

1 Answers1

1

You are trying to use the BackupManager directly and you cannot do that without the android.permission.BACKUP permission. That permission is only granted to apps signed with the platform key (basically system apps).

You are requesting the permission in your manifest but if you watch the logs while you install you should see the "Not granting permission" warning for your app.

So in the end your code looks generally correct but you are just getting a security exception when trying to call the protected methods.

Hayes Haugen
  • 822
  • 1
  • 7
  • 7