Android : Dropbox datastore API - Record invisible for device which has not created it

on Saturday, November 1, 2014


I'm developing an app which should be able to synchronize datastores between several devices.


In this way, I implement a listener on a datastore manager in order to catch creation or modification of datastores from whatever the devices.


The listener works well, each changement on datastore are perceived through all devices.


To display the data gotten from datastores, the app has to find out a record called "titre" present inside of each datastore. But here I cannot understand the problem. When the datastore is created from a device, this device can identify the record "titre", whereas the others cannot.


I give you the concrete example of my problem:



  • Device A create the datastore X with a record field "titre" => when the code call tab.get("titre") it is not equal to null

  • Now, if device B gets datastore X and calls tab.get("titre"), then the result is equal to null


Concerning roles, all datastores are created with the same permissions given below:



try {
datastoreTitle = mDatastoreManager.createDatastore();
datastoreTitle.setRole(DbxPrincipal.PUBLIC, DbxDatastore.Role.EDITOR);
} catch (DbxException e) {
e.printStackTrace();
}


Would you have an idea of my problem? Thank you for your help!


The bit of code raising the issue is:



mDatastoreManager.addListListener(new DbxDatastoreManager.ListListener() {
@Override
public void onDatastoreListChange(DbxDatastoreManager dbxDatastoreManager) {

List<TitleList> listInBDD = db.getTitleSQliteHelper(); //1
Set<DbxDatastoreInfo> datastorePresent = null;
try {
datastorePresent = mDatastoreManager.listDatastores(); //2
} catch (DbxException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Iterator<DbxDatastoreInfo> mdbxDatastoreInfoIterator = datastorePresent.iterator() ;

while (mdbxDatastoreInfoIterator.hasNext()){

DbxDatastoreInfo mdbxDatastoreInfo = mdbxDatastoreInfoIterator.next();
boolean find = false ;
Log.d("Test 1 - delete Datastore => mdbxDatastoreInfo.id :" , mdbxDatastoreInfo.id ) ;

for (TitleList titleFound : listInBDD){
if (titleFound.idDbx.equals(mdbxDatastoreInfo.id)){
Log.d("Test 2 - delete Datastore => TitleList :" , titleFound.nom.toString() ) ;

find = true ;
}
}

if ( !find ){
Log.d("Delete absent datastore inside of the BDD : " , mdbxDatastoreInfo.id ) ;
try {
DbxDatastore dbxStore = mDatastoreManager.openDatastore(mdbxDatastoreInfo.id);
Toast.makeText(MainActivity.this, dbxStore.getId(), Toast.LENGTH_LONG).show();
DbxTable tab = dbxStore.getTable("table_de_courses");
// Toast.makeText(MainActivity.this, new Boolean(tab.get("titre").getString("titre")).toString(), Toast.LENGTH_LONG).show();
//

// !!! The problem is here, tab.get("titre") = null when the device calling it haven't created the datastore containing this record !!!
if ( tab.get("titre") != null ){
// DbxRecord rec = tab.get("titre");
TitleList tit = new TitleList(tab.get("titre").getString("titre"));
tit.setConnectDropbox();
tit.setIdDbx(mdbxDatastoreInfo.id);
db.addLists(tit);
}
// mDatastoreManager.deleteDatastore(mdbxDatastoreInfo.id) ;//4
} catch (DbxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

updateList();
}
});

0 comments:

Post a Comment