Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have never worked with the Core API but I am both able to download and receive files.</p> <p>It is though worth mentioning, that the intention of the Sync API (likely also the core), is not to keep the local files up-to-date. Rather it is designed to let you retrieve the files available on Dropbox and download on the fly.</p> <p>My use case needed the Dropbox files to be retrieve locally, so I run a sync algorithm that run through all the Dropbox files, checks modified and size and downloads all the, either new, or modified files to SD. The downloading is done using IntentServices. Issuing an IntentService for each file that needs to be downloaded.</p> <p>So, for one way sync, Sync API works fine. The other way should be possible too, though I assume harder to manage. </p> <p>Bottom line being that you should be able to do it but you have to do a lot of lifting yourself.</p> <p>The few questions I have seen with the Core API, I have not spotted any huge differences, other than the Sync API lives in a specific Dropbox folder "Dropbox/apps/yourapp", Core API does not. </p> <p>If that is the case I would recommend Sync API as it seems to be simpler to work with.</p> <p>I am willing to post my code for the one way sync if you choose to go for it :)</p> <p><strong>Edit:</strong> Added my code for writing to Dropbox</p> <pre><code>public class DropboxWriter { private static final String TAG = "DropboxWriter"; public static boolean writeAssetBinary(Context context, String assetFile, DbxFile toFile) { String tempsdpath = Environment.getExternalStorageDirectory() .toString() + "/temp"; AssetManager assetManager = context.getAssets(); OutputStream outputStream = null; InputStream inputStream = null; try { inputStream = assetManager.open(assetFile); outputStream = new FileOutputStream(tempsdpath + "/" + assetFile); byte buf[] = new byte[1024]; int len; while ((len = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, len); } } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { } } if (outputStream != null) { try { outputStream.flush(); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } try { File file = new File(tempsdpath, assetFile); toFile.writeFromExistingFile(file, false); return true; } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } finally { toFile.close(); } return false; } public static boolean writeAssetText(Context context, String assetFile, DbxFile toFile) { AssetManager assetManager = context.getAssets(); ByteArrayOutputStream outputStream = null; InputStream inputStream = null; try { inputStream = assetManager.open(assetFile); outputStream = new ByteArrayOutputStream(); byte buf[] = new byte[1024]; int len; while ((len = inputStream.read(buf)) != -1) { outputStream.write(buf, 0, len); } outputStream.flush(); outputStream.close(); inputStream.close(); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } try { toFile.writeString(outputStream.toString()); return true; } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } finally { toFile.close(); } return false; } } </code></pre> <p>Up until this point I have only needed to write files from assets but could easily be rewritten to write from any other file.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload