Java Question Beginners problems building a library

DonManfred

Expert
Licensed User
Longtime User
Hello java-masters,

i´m actually building a library and i have kind of problems. I just want to know whether i´m doing that right or whether i´m doing it wrong because......

B4X:
    @SuppressWarnings("rawtypes")
    public List ListDatastores() throws DbxException{
        Set<DbxDatastoreInfo> ds = mDatastoreManager.listDatastores();
        List l = new List();
        l.Initialize();
        for (DbxDatastoreInfo dsi : ds) {
            HashMap m = new HashMap();
            m.put("id", dsi.id);
            m.put("mtime", dsi.mtime);
            m.put("title", dsi.title);
            m.put("hashcode", dsi.hashCode());
            l.Add(m);
        }
        //l.getObject().addAll(ds);
        return l;
    }

This code works in principle... But it seems that i just get ONE Datastore back to b4a.
B4X:
    Dim dslist As List = manager.ListDatastores
    Log("dslistsize="&dslist.Size)
    For i = 0 To dslist.Size -1
        Log(dslist.Get(i))
    Next
{mtime=null, id=default, title=null, hashcode=-1502101888}

It seems that this is just the default-datastore from the device but not one of the Datastores i can see in dropboxs developerconsole. But i was expecting exactly this datastores...

dbxdatastores_002.png


Could that be?

Maybe i´m doing the initialization of the datastore wrong with the manager
java-code
B4X:
    /**
     * Links the application with the user's Dropbox account.
     *If the account was not linked before then the user will be shown an authentication form.
     *The AccountReady event will be raised when the account is ready.
     */
    public void LinkAccount(final BA ba) {
        if (manager.hasLinkedAccount()) {
         try {
                // Use Dropbox datastores
                mDatastoreManager = DbxDatastoreManager.forAccount(manager.getLinkedAccount());
            } catch (DbxException.Unauthorized e) {
                System.out.println("Account was unlinked remotely");
            }
            if (mDatastoreManager == null) {
                 // Account isn't linked yet, use local datastores
                mDatastoreManager = DbxDatastoreManager.localManager(manager);
             }
             //try {
             //    datastore = mDatastoreManager.openDefaultDatastore();
             //} catch (DbxException e) {
             //  System.out.println("Account was unlinked remotely");
            //}
            waitForFileSystem(ba);
            return;
        }
       
         ion = new IOnActivityResult() {

            @Override
            public void ResultArrived(int resultCode, Intent intent) {
                if (resultCode != Activity.RESULT_OK)
                    ba.raiseEvent(DbxAccountManagerWrapper.this, eventName + "_accountready", false);
                else
                    waitForFileSystem(ba);
            }

        };
        try {
            ba.startActivityForResult(ion, null);
        } catch (NullPointerException npe) {
            //required...
        }
        BA.SharedProcessBA sba = ba.sharedProcessBA;
        try {
            Field f = BA.SharedProcessBA.class.getDeclaredField("onActivityResultCode");
            f.setAccessible(true);
            int requestCode = f.getInt(sba) - 1;
            manager.startLink((Activity)ba.sharedProcessBA.activityBA.get().activity, requestCode);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
I´m not sure whether i did that right or not. It´s my attempt of integrating datastores into the program-flow (using the LinkAccount-command in the dropboxsync-library (which i am extending here)

Probably it´s totally wrong

If someone have any kind of comment, suggestions, help, whatever; i would really appreciate any kind of help/tips/answers

Thank you!
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Note that you should use anywheresoftware.b4a.objects.collections.Map instead of HashMap though it is not related to this issue.
will have a look at this. thanx!
The ListDatastores code is correct which means that Dropbox returned a single item.
Ok, then i believe i have an local-datastore only. Not an linked one to my dropbox-account
B4X:
if (mDatastoreManager == null) {
  // Account isn't linked yet, use local datastores
  mDatastoreManager = DbxDatastoreManager.localManager(manager); ' This seems to be the active datastoremanager.
}

Sounds for me that my attempt
B4X:
try {
                // Use Dropbox datastores
                mDatastoreManager = DbxDatastoreManager.forAccount(manager.getLinkedAccount());
            } catch (DbxException.Unauthorized e) {
                System.out.println("Account was unlinked remotely");
            }
does not results in an linked DatastoreManager (mDatastoreManager = NULL)
 
Top