Dropbox Sync API - 如何手动同步?

时间:2013-12-10 07:44:41

标签: android dropbox

我正在尝试在我的Android应用中实现Dropbox Sync API。我想在Click Events上手动执行同步。我写了这段代码:br />

private class BackgroundSyncManager extends AsyncTask<String, String, String>
{

    private boolean isSynced = false;

    private ProgressDialog pd;

    public BackgroundSyncManager(Context ctx)
    {
        pd = new ProgressDialog(ctx);
        pd.setTitle("Downlaoding in Progress...");
        pd.setCancelable(false);
        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }
    @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
        pd.dismiss();
        sync_Button.setVisibility(View.GONE);
    }

    @Override
    protected void onProgressUpdate(String... values) {
        // TODO Auto-generated method stub
        super.onProgressUpdate(values);
        pd.setProgress(Integer.parseInt(values[0]));
    }

    protected String doInBackground(String... params) {
        // TODO Auto-generated method stub

        try
        {
            pd.show();
            mDbFileSystem.syncNowAndWait();
                            isSynced = true;

        }
        catch(Exception e)
        {
            isSynced = false;
            Log.e(TAG, "Error Occured While Syncing !, Error = "+e.toString());
        }
        return "";
    }
}

但是,它给我一个Error,这是我的Logcat说的:

12-10 11:34:23.311: E/Main Activity(15464): Error Occured While Syncing !, Error = java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

我在进行手动同步错误,或者在此实施中是否存在问题? 非常感谢任何帮助,谢谢。

0 个答案:

没有答案