<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Download file from Dropbox to local android Java in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6962#M294</link>
    <description>&lt;P&gt;Hello Steve,&lt;BR /&gt;
Thank you for your answer. Actually the program import first the files to the local folder then it open the files. These files are database files.&lt;BR /&gt;
The program crashes because it cannot find the local files. But this problem occurs only after the first run. I mean if I uninstall the application then I re install, it crashes. But if I just restart after the crash, it works, the local files were downloaded.&lt;/P&gt;

&lt;P&gt;Here the error stack trace:&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): FATAL EXCEPTION: main&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): Process: com.wataiso.labnotebook, PID: 24240&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): java.lang.RuntimeException: Unable to resume activity {com.wataiso.labnotebook/com.wataiso.labnotebook.TableauDeBord}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2791)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2820)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.os.Handler.dispatchMessage(Handler.java:102)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.os.Looper.loop(Looper.java:136)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.main(ActivityThread.java:5050)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at java.lang.reflect.Method.invokeNative(Native Method)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at java.lang.reflect.Method.invoke(Method.java:515)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at dalvik.system.NativeStart.main(Native Method)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.wataiso.labnotebook.DatabaseHelper.getInfo(DatabaseHelper.java:477)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.wataiso.labnotebook.TableauDeBord.showLinkedViewDB(TableauDeBord.java:607)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.wataiso.labnotebook.TableauDeBord.onResume(TableauDeBord.java:226)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.Activity.performResume(Activity.java:5310)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2781)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    ... 10 more&lt;/P&gt;</description>
    <pubDate>Wed, 31 Dec 2014 09:21:37 GMT</pubDate>
    <dc:creator>Nicolas L.</dc:creator>
    <dc:date>2014-12-31T09:21:37Z</dc:date>
    <item>
      <title>Download file from Dropbox to local android Java</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6960#M292</link>
      <description>&lt;P&gt;I spent some days on this code without finding the solution. Could you help me please?&lt;/P&gt;

&lt;P&gt;I want to download a file from a Dropbox account to the application storage (local memory). When I open the file for the first time, the application crashes then when I restart the application, the file can be open from the local memory.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;private void ImportDB(String nameDB)
  {
          try {
              File data = Environment.getDataDirectory();

                  //Local file
                  String backupDBPath = "//data//[Package name]//databases//"+nameDB;
                  File backupDB = new File(data, backupDBPath);

                  //Dropbox file                      
                  DbxPath testPath = new DbxPath(DbxPath.ROOT, nameDB);
                  DbxFileSystem dbxFs = DbxFileSystem.forAccount(mDbxAcctMgr.getLinkedAccount());


                  DbxFile testFile = dbxFs.open(testPath);

                    FileChannel src = testFile.getReadStream().getChannel();
                    FileChannel dst = new FileOutputStream(backupDB).getChannel();

                     //Transfert to local
                      dst.transferFrom(src, 0, src.size());

                      //close
                      src.close();
                      dst.close();
                      testFile.close();
          }
          catch (Exception e)
          {

          }
  }
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I guess it is a question of synchronization: the file is not yet copied when I try to open it. I tried this code for waiting the file but it doesn't work, the program stays in the while loop:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Thread mThread = new Thread()
            {
            @SuppressLint("NewApi") @Override
            public void run()
            {
                    //open the local file
                    File data = Environment.getDataDirectory();
                    String currentDBPath = "//data//[Package name]//databases//"+nameFileDB";
                    File currentDB = new File(data, currentDBPath);

                    // test when the file is downloaded
                    while (!currentDB.exists())
                    {
                        Log.i("tag", "In loop");

                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                    //CODE TO OPEN THE FILE HERE

                }
            }
            };
            mThread.start();
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I already tried the AsyncTask and I have the same problem. I guess when the download from Dropbox is ordered, the program goes to the onPostExecute but it doesn't mean that the downloading is finished. I think I must have a listener on when the file is downloaded to the local memory. &lt;/P&gt;

&lt;P&gt;Any Ideas???&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:46:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6960#M292</guid>
      <dc:creator>Nicolas L.</dc:creator>
      <dc:date>2019-05-29T09:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Download file from Dropbox to local android Java</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6961#M293</link>
      <description>&lt;P&gt;"When I open the file for the first time, the application crashes..." What's the stack trace of the crash?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Dec 2014 05:22:04 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6961#M293</guid>
      <dc:creator>Steve M.</dc:creator>
      <dc:date>2014-12-30T05:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: Download file from Dropbox to local android Java</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6962#M294</link>
      <description>&lt;P&gt;Hello Steve,&lt;BR /&gt;
Thank you for your answer. Actually the program import first the files to the local folder then it open the files. These files are database files.&lt;BR /&gt;
The program crashes because it cannot find the local files. But this problem occurs only after the first run. I mean if I uninstall the application then I re install, it crashes. But if I just restart after the crash, it works, the local files were downloaded.&lt;/P&gt;

&lt;P&gt;Here the error stack trace:&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): FATAL EXCEPTION: main&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): Process: com.wataiso.labnotebook, PID: 24240&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): java.lang.RuntimeException: Unable to resume activity {com.wataiso.labnotebook/com.wataiso.labnotebook.TableauDeBord}: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2791)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2820)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.os.Handler.dispatchMessage(Handler.java:102)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.os.Looper.loop(Looper.java:136)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.main(ActivityThread.java:5050)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at java.lang.reflect.Method.invokeNative(Native Method)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at java.lang.reflect.Method.invoke(Method.java:515)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:805)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:621)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at dalvik.system.NativeStart.main(Native Method)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240): Caused by: android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.database.AbstractCursor.checkPosition(AbstractCursor.java:426)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:136)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:50)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.wataiso.labnotebook.DatabaseHelper.getInfo(DatabaseHelper.java:477)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.wataiso.labnotebook.TableauDeBord.showLinkedViewDB(TableauDeBord.java:607)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at com.wataiso.labnotebook.TableauDeBord.onResume(TableauDeBord.java:226)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1192)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.Activity.performResume(Activity.java:5310)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2781)&lt;BR /&gt;
12-31 10:07:46.461: E/AndroidRuntime(24240):    ... 10 more&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2014 09:21:37 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6962#M294</guid>
      <dc:creator>Nicolas L.</dc:creator>
      <dc:date>2014-12-31T09:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: Download file from Dropbox to local android Java</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6963#M295</link>
      <description>&lt;P&gt;In general, to download a file, you need to open it and hold it open while waiting for the download to complete. (Everything in the Sync SDK is asynchronous.)&lt;/P&gt;

&lt;P&gt;So the usual pattern here is to open the file, register a listener on that file, wait for &lt;CODE&gt;getNewerStatus().isCached&lt;/CODE&gt; to be true, and then call &lt;CODE&gt;update()&lt;/CODE&gt; on the file. At that point, you should be able to read the latest file contents. (If you read before that, you'll either see cached data if available or you'll perhaps hang the UI thread waiting for network I/O.)&lt;/P&gt;

&lt;P&gt;I would actually expect your original code to work (but hang the thread), since &lt;CODE&gt;getReadStream()&lt;/CODE&gt; should block if there's no cached data.&lt;/P&gt;

&lt;P&gt;Can you confirm that after &lt;CODE&gt;dst.transferFrom(src, 0, src.size());&lt;/CODE&gt;, the file is empty (or there is some other problem with it) to narrow down the issue?&lt;/P&gt;</description>
      <pubDate>Sat, 03 Jan 2015 07:25:06 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Download-file-from-Dropbox-to-local-android-Java/m-p/6963#M295</guid>
      <dc:creator>Steve M.</dc:creator>
      <dc:date>2015-01-03T07:25:06Z</dc:date>
    </item>
  </channel>
</rss>

