在同步内部存储TXT文件以txt文件中的Dropbox的Dropbox API [英] sync txt file in internal storage with txt file in dropbox dropbox api

查看:216
本文介绍了在同步内部存储TXT文件以txt文件中的Dropbox的Dropbox API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要同步在Android的内部存储(或SD卡为此事)一个txt文件并将其自动同步到我的Dropbox一个txt。我用的Dropbox API,但没有坚持就如何实现这一目标。帮助需要请。

I want to sync a txt file in android internal storage (or sdcard for that matter) and have it automatically sync to a txt in my dropbox. i've used dropbox api but don't have hold on on how to achieve this. help needed please.

更新:

下面是我的函数来获取TXT内容LogCat中现在:

Here's my function to get the txt content to LogCat for now:

public void getFromDbx(){

        try {
            mDbxAcctMgr.startLink((Activity)this, REQUEST_LINK_TO_DBX);

            final String TEST_DATA = " Database does not exist yet";

            final String TEST_FILE_NAME = "data.txt";
            DbxPath testPath = new DbxPath(DbxPath.ROOT, TEST_FILE_NAME);

            // Create DbxFileSystem for synchronized file access.
            DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());

            // Print the contents of the root folder.  This will block until we can
            // sync metadata the first time.

            //dont need this code -- ahmed

            // Create a test file only if it doesn't already exist.
            if (!dbxFs.exists(testPath)) {
                DbxFile testFile = dbxFs.create(testPath);
                try {
                    testFile.writeString(TEST_DATA);
                } finally {
                    testFile.close();
                }

            }

            // Read and print the contents of test file.  Since we're not making
            // any attempt to wait for the latest version, this may print an
            // older cached version.  Use getSyncStatus() and/or a listener to
            // check for a new version.
            if (dbxFs.isFile(testPath)) {
                String resultData;
                DbxFile testFile = dbxFs.open(testPath);
                try {
                    resultData = testFile.readString();
                } finally {
                    testFile.close();
                }

                Log.i("dbx",resultData);
            } else if (dbxFs.isFolder(testPath)) {

            }
        } catch (IOException e) {

        }

我的OnCreate:

My OnCreate:

super.onCreate(savedInstanceState);
        setContentView(R.layout.main_screen);

        //connect dbx to account
                mDbxAcctMgr = DbxAccountManager.getInstance(getApplicationContext(), appKey, appSecret);

                //get data from ems_data.txt from dropbox account
                getFromDbx();

我的onActivityResult:

My OnActivityResult:

public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == REQUEST_LINK_TO_DBX) {
            if (resultCode == Activity.RESULT_OK) {
                getFromDbx();
            } else {
                Log.i("dbxems", "Link to Dropbox failed or was cancelled.");
            }
        } else {
            super.onActivityResult(requestCode, resultCode, data);
        }
    }

我的清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.testdatabaseactivity"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.CALL_PHONE" >

    </uses-permission>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:debuggable="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.testdatabaseactivity.TestDatabaseActivity"
            android:label="@string/app_name" >
            <intent-filter>
            </intent-filter>
        </activity>

        <instrumentation
            android:name="android.test.InstrumentationTestRunner"
            android:label="your tests label"
            android:targetPackage="com.example.testdatabaseactivity" />

        <uses-library android:name="android.test.runner" />

        <activity
            android:name="com.example.testdatabaseactivity.MainScreenActivity"
            android:label="@string/title_activity_main_screen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.testdatabaseactivity.SearchByName"
            android:label="@string/title_activity_search_by_name"
            android:windowSoftInputMode="stateHidden" >
        </activity>

        <activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
        <activity
            android:name="com.dropbox.client2.android.AuthActivity"
            android:launchMode="singleTask" >
            <intent-filter>
                <data android:scheme="db-KEY_HERE" />
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.BROWSABLE" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <service
            android:name="com.dropbox.sync.android.DbxSyncService"
            android:enabled="true"
            android:exported="false"
            android:label="Dropbox Sync" />
    </application>

</manifest>

编辑:没有错误,应用程序显示屏幕权威性,我点击允许,然后什么也没有发生。我可以preSS允许10倍,什么都不会发生在所有..

there is no error, the app shows the auth screen, I click allow and then nothing happens. I can press allow 10 times and nothing happens at all..

推荐答案

getFromDbx ,你叫 STARTLINK ,这带来了连结帐户的用户界面。当成功,你的的onActivityResult 执行,在那里你叫 getFromDbx ,要求 STARTLINK 一次。 :-)看起来像一个无限循环给我。

In getFromDbx, you call startLink, which brings up the UI to link an account. When that succeeds, your onActivityResult is executed, where you call getFromDbx, which calls startLink again. :-) Looks like an infinite loop to me.

这篇关于在同步内部存储TXT文件以txt文件中的Dropbox的Dropbox API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆