Android:写包裹的例外?

时间:2014-07-14 19:59:20

标签: android file

我的应用程序代码中出现以下 Logcat错误

07-14 20:17:15.026: E/DatabaseUtils(814): Writing exception to parcel
07-14 20:17:15.026: E/DatabaseUtils(814): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
07-14 20:17:15.026: E/DatabaseUtils(814):   at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14608)

我试过通过在清单中添加以下权限来解决问题,如错误中所述:

 <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL"/>

然而,它没有解决问题?

相关代码:

尝试将DB文件传输到SD卡的类:

public class ExportDatabaseFileTask extends AsyncTask<String, Void, Boolean> {

    //Default constructor
    public ExportDatabaseFileTask() {

    }

    //delete if necessary
    //private final ProgressDialog dialog = new ProgressDialog(null);


    // can use UI thread here
    protected void onPreExecute() {
//      this.dialog.setMessage("Exporting database...");
//      this.dialog.show();
    }

    // automatically done on worker thread (separate from UI thread)
    protected Boolean doInBackground(final String... args) {

        //original database file location
        File dbFile = new File(Environment.getDataDirectory()
                + "/com.example.multapply/databases/MultapplyDatabase.db");

        //the destination file location
        File exportDir = new File(Environment.getExternalStorageDirectory(), "");
        if (!exportDir.exists()) {
            exportDir.mkdirs();
        }


        File file = new File(exportDir, dbFile.getName());
        try {
            file.createNewFile();
            this.copyFile(dbFile, file);
            return true;
        } catch (IOException e) {
            Log.e("mypck", e.getMessage(), e);
            return false;
        }
    }

    // can use UI thread here
    protected void onPostExecute(final Boolean success) {
//      if (this.dialog.isShowing()) {
//          this.dialog.dismiss();
//      }
//      if (success) {
//          Toast.makeText( null, "Export successful!", Toast.LENGTH_SHORT)
//                  .show();
//      } else {
//          Toast.makeText(null, "Export failed", Toast.LENGTH_SHORT).show();
//      }
    }

    void copyFile(File src, File dst) throws IOException {
        FileChannel inChannel = new FileInputStream(src).getChannel();
        FileChannel outChannel = new FileOutputStream(dst).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } finally {
            if (inChannel != null)
                inChannel.close();
            if (outChannel != null)
                outChannel.close();
        }
    }

}

实例化此类:

/**
             * CRUD Operations
             * */
            // Inserting Contacts
            Log.d("Insert: ", "Inserting ..");

            db.addScore(new Score(UserName.getUserName(), score, System.currentTimeMillis() ));

            //attempting to export the file to the sd card
            ExportDatabaseFileTask task = new ExportDatabaseFileTask();
            task.execute();

完全堆积的错误痕迹:

07-14 21:48:00.903: E/DatabaseUtils(814): Writing exception to parcel
07-14 21:48:00.903: E/DatabaseUtils(814): java.lang.SecurityException: Permission Denial: get/set setting for user asks to run as user -2 but is calling from user 0; this requires android.permission.INTERACT_ACROSS_USERS_FULL
07-14 21:48:00.903: E/DatabaseUtils(814):   at com.android.server.am.ActivityManagerService.handleIncomingUser(ActivityManagerService.java:14608)
07-14 21:48:00.903: E/DatabaseUtils(814):   at android.app.ActivityManager.handleIncomingUser(ActivityManager.java:2258)
07-14 21:48:00.903: E/DatabaseUtils(814):   at com.android.providers.settings.SettingsProvider.call(SettingsProvider.java:663)
07-14 21:48:00.903: E/DatabaseUtils(814):   at android.content.ContentProvider$Transport.call(ContentProvider.java:325)
07-14 21:48:00.903: E/DatabaseUtils(814):   at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:275)
07-14 21:48:00.903: E/DatabaseUtils(814):   at android.os.Binder.execTransact(Binder.java:404)
07-14 21:48:00.903: E/DatabaseUtils(814):   at dalvik.system.NativeStart.run(Native Method)

0 个答案:

没有答案