Kaa SDK Android, java class manual - Problem with android context

507 views
Skip to first unread message

Gianluca Barbera

unread,
Nov 13, 2015, 11:39:52 AM11/13/15
to Kaa project
Hi,
Sorry, I'm still me.
To achieve a university project we chose kaa as IoT platform, we would like to communicate different devices (raspberry Pi, Android, and perhaps others in the future) with kaa.

3 big questions:

1 - Can we communicate only via REST with my application? (Read, write and update data)? Can I completely ignore Kaa SDK for the interaction with my Kaa instance?

2 - I know there is a better solution: using Kaa SDK (Android, Java, C++ and C), but how it works? I would like to find a Kaa SDK reference for android because I don't know how to communicate with my kaa istance... I have already read the first application tutorial that work fine on desktop but i am not able to translate it for "Android Context"

3 - Can i access via DB to the data collected by Kaa?

Thank you so much in advance for the help

- Gianluca

Andrew Shvayka

unread,
Nov 13, 2015, 12:36:22 PM11/13/15
to Kaa project
Hi!

1) Kaa REST API interface is designed for administration purposes. For example, you can create notification topics, send notification and update device configuration via REST API interface.
    Kaa Endpoints communicate to Kaa service via SDK. This enables auto-generated APIs, security, efficient data serialization/deserialization, etc.
2) Kaa SDK communicates to endpoints via TCP and/or HTTP protocol. Communication layer is embedded to the SDK. You are able to generates SDKs in Admin UI interface of your Kaa Server installation (sandbox or cluster).
    Android SDK API is quite similar with Java SDK API. You just initialize it with platform specific context. You can take a look at Cell Monitor application (data collection feature) or GPIO Control (event feature). This webinar might also be useful to get started. 
    Sample code for Kaa client initialization can be found here.
3) Yes! You can configure where to put the data. Take a loot at this article and one of our data collection webinars.

Thanks,
Andrew

Gianluca Barbera

unread,
Nov 17, 2015, 9:43:21 AM11/17/15
to Kaa project
Hi

thank you very much for your answer. But I still have some problems to create my own Android application...

Where can I find a complete Android SDK API guide? (I have already seen this page)

Thank you again in advance

- Gianluca

Dmitry Sergeev

unread,
Nov 19, 2015, 3:52:04 AM11/19/15
to Kaa project
Hello, Glanluca!

Long story short: you can use same Javadoc for "Android" and "Java" API.
Programming guide is placed here.

So, there is no difference between "Java SDK" and "Android SDK" API. The only way they differ is Android context. 
You can observe all Android-specific parts here

Thank for your interest in Kaa!

вторник, 17 ноября 2015 г., 16:43:21 UTC+2 пользователь Gianluca Barbera написал:

Gianluca Barbera

unread,
Nov 19, 2015, 5:49:53 AM11/19/15
to Kaa project
Thank you for your help, now I get this error from Android Studio trying a simple Endpoint Profile Registration

FATAL EXCEPTION: main 
java.lang.NoSuchMethodError: java.lang.String.isEmpty
    at org.kaaproject.kaa.client.KaaClientProperties.parseBootstrapServers(KaaClientProperties.java:155)
    at org.kaaproject.kaa.client.KaaClientProperties.getBootstrapServers(KaaClientProperties.java:130)
...


My code is simply

public class KaaEndpoint extends Application {
Profile profile;

private static Context mContext;
private KaaClient mClient;

public void initProfile () {
mClient = Kaa.newClient(new AndroidKaaPlatformContext(this), new SimpleKaaClientStateListener());
profile = new Profile("String_ID", "String_Name", "Type_AndroidPlarform" , false);

// Simple implementation of ProfileContainer interface that is provided by the SDK
mClient.setProfileContainer(new ProfileContainer() {
@Override
public Profile getProfile() {
return profile;
}
});

// Starts Kaa
mClient.start();
profile.setMaster(true);
mClient.updateProfile();
}
}

With a call to initProfile in my Main Activity.. What am I doing wrong?

Thanks in advance

- Gianluca


Denis Kimcherenko

unread,
Nov 19, 2015, 6:14:05 AM11/19/15
to Kaa project
Hi,

It seems like your Android project is configured with a wrong Java version.
Java version must be 6+.

Gianluca Barbera

unread,
Nov 19, 2015, 8:15:17 AM11/19/15
to Kaa project
Hi 

- I am using jdk 1.8.0_40 and Gradle 2.4
- No error in compiling phase
- Source and Target Compatibility forced to 1.7

I should have the latest version, right?

- Gianluca

Gianluca Barbera

unread,
Nov 19, 2015, 8:29:02 AM11/19/15
to Kaa project
If I use the same code changing Android SDK Version from Froyo to Marshmallow I still get an error

Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference

Dmitry Sergeev

unread,
Nov 19, 2015, 9:45:21 AM11/19/15
to Kaa project
1) What is the minimum sdk version in your project?
String.isEmpty method first appeared in Android 2.3

2) It looks like you have problems with Android Context. Referring to Application docs:

There is normally no need to subclass Application. In most situation, static singletons can provide the same functionality in a more modular way. If your singleton needs a global context (for example to register broadcast receivers), the function to retrieve it can be given a Context which internally uses Context.getApplicationContext() when first constructing the singleton.

So I guess you're giving wrong object to new AndroidKaaPlatformContext(this) constructor.
 

четверг, 19 ноября 2015 г., 15:29:02 UTC+2 пользователь Gianluca Barbera написал:

Gianluca Barbera

unread,
Nov 20, 2015, 1:47:57 PM11/20/15
to Kaa project
Hi

I forgot to insert
public void onCreate ()
{
super.onCreate();
mContext = this;
}

but i still get the same error...

I only want to do a simple profile registration, I am trying to adapt the examples code Android Notification and similars..

Dmitry Sergeev

unread,
Nov 27, 2015, 3:52:30 AM11/27/15
to Kaa project
Hello again, Gianluca!

You're passing passing wrong Context to AndroidKaaPlatformContext constructor.

You need to pass Context from Activity where you are using KaaEndpoint class.

I resolved your problem by the next steps:

1) In KaaEndpoint create constructor with Context param:
public KaaEndpoint(Context context) {
    mContext
= context;
}

 2) Pass mContext to AndroidKaaPlatformContext constructor:

mClient = Kaa.newClient(new AndroidKaaPlatformContext(mContext), new SimpleKaaClientStateListener())

3) Finally, in onCreate() method of MainActivity instantiate:

KaaEndpoint endpoint = new KaaEndpoint(this);
endpoint
.initProfile();

Good luck!

Dmitry

;пятница, 20 ноября 2015 г., 20:47:57 UTC+2 пользователь Gianluca Barbera написал:
Reply all
Reply to author
Forward
0 new messages