0

我想将 txt 文件同步到我的 android 应用程序的内部存储中的文件。现在我正在尝试将 txt 文件读取到 logcat 以查看会发生什么。它显示了 Dropbox 窗口,在该窗口中请求此应用程序“在您的 Dropbox 中创建文件夹”的权限。当我单击允许时,没有任何反应。顶部的 url 会发生一些变化,最后会显示“连接”一段时间,然后它会恢复到“允许”屏幕。请帮忙。

这是我现在将 txt 内容获取到 LogCat 的函数:

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) {

        }

我的创建:

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:

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

0 回答 0