Using DreamFactorySoftware with Android Studio


#1

I’m trying to use DreamFactory from GitHub with Android Studio, but my attempts haven’t been successful so far.

How can I import this library and use it for connecting to dream.factory.cloud ?

The guide is for Eclipse, and not for Android Studio. Also, the sample app does not use Gradle. I don’t know how to fix this, and I would need some pointers.


#2

We have not used Android Studio before, only Eclipse. Once you accomplish this import, please post back with a tutorial so other users can benefit! Same goes with Gradle integration. The community would certainly appreciate your experience.


#3

Hi,
any news on this topic?

Thanks


#4

We have uploaded the sample app converted to Android Studio here:

[link removed by admin. no longer valid]


#5

Hi,
thanks for the Android Studio project, it imports with no errors.

But I’m facing an error with the session after logout. I mean, I get in first time OK, I logout, and then when I login back again, I select either “To-Do List Demo” or “File APIs Demo” and I always get a 401 from the server, with message “There is no valid session for the current request.”.
This repeats until I close the application (sweep from the alt+tab alike list of running apps at android).

Any idea what might be happening?

Thanks,
Emmanuel.


#6

Message says there is no valid session, this means when app is getting logged out session is cleared but app/activity is not getting destroyed. Try to Close activity and check session before going to next screen. If session in null then go with login flow again.

Let me know if works.


#7

Hi,
I found the root cause of the error. At logout there’s a hashmap entry from defaultHeaderMap @ ApiInvoker that needs to be removed. As it is a private var, I had to modify the SDK:

public void removeDefaultHeader(String key) {
	defaultHeaderMap.remove(key);
}

In logout method, at BaseActivity, a new line was added:

ApiInvoker.getInstance().removeDefaultHeader("X-DreamFactory-Session-Token");

Also, I replaced all the SharedPreferences clear values from empty to null, because there’s at least one if that wasn’t matching at MainActivity, triggering an additional HTTP request to the DSP:

    String oldSessionKey = PrefUtil.getString(getApplicationContext(), IAppConstants.SESSION_ID, null);
    String userID = PrefUtil.getString(getApplicationContext(), IAppConstants.EMAIL, null);
    String userPass = PrefUtil.getString(getApplicationContext(), IAppConstants.PWD, null);
    String dspUrl = PrefUtil.getString(getApplicationContext(), IAppConstants.DSP_URL, null);

    if(oldSessionKey == null &&  userID == null && userPass == null && dspUrl == null){

I’m not sure if this is the most elegant or suggested approach, so any comment will be appreciated.

Thanks,
Emmanuel.


#8

thanks, we’ll take a look at the SDK.


#9

Removing session, userID and pwd from preference will do the job.


#10

Hi I am new to this dream factory environment. I had downloaded Sample app which is converted to Android Studio through your link Can you help me how to get connected to the service that I created in dream factory through android app.


#11

Please do not use this linked tool. It is for an End of Life version of DreamFactory. Instead check out the sample apps and tutorials available here.
http://wiki.dreamfactory.com/DreamFactory/Example_Apps
http://wiki.dreamfactory.com/DreamFactory/Tutorials