Spark-sdk-android

I just downloaded the spark-sdk-android zip and open & build with Android Studio. I also checked the doc and it indicates it requires

  1. sparkCloud.logIn
  2. sparkCloud.getDevices
    before it can call sparkDevice.getVariable and other cloud functions.

Since I am newbie to Android Apps (previously I was using the JS on PC for testing and use access token without perform user login). Is there a simple way to just provide access token to Spark API call and perform the access to device ?

1 Like

OK, I got it working by modifying the example ParticleDevice number to be my device. I did not notice it was fixed id.
But now I have another question someone had asked but no answer yet.

The current example is in Async mode, how could we run it in Sync mode if we can ?
I tried the following but failed.

private ParticleCloud sparkCloud;
sparkCloud.login(email, password);

The error said “unreopened exception ParticalCloudExeception”

Reason I try to do in sync mode is, how can I know my login is done and I could call sparkCloud.getDevice();
I would suppose I need to call this inside the onSuccess(), correct ??

The ParticleCloud and ParticleDevice API is intentionally 100% blocking and synchronous. The only reason for the Async class is to make it easy to call these blocking API methods off the main/UI thread.

If you have a series of calls you want to make in sequence before returning, I recommend looking into Android’s AsyncTask class: http://developer.android.com/reference/android/os/AsyncTask.html

Hope this helps!

I try to include the "cloudsdk" to my Android project but having issues. If I used following in build.gradle, it is working fine.

compile 'io.particle:cloudsdk:0.2.2'

However, if I want to include source files in my project, it failed the build. Here are when my steps.

  1. add > compile project(':cloudsdk') in build.gradle
    2.downloaded the zip for Spark-sdk-android.
  2. Add "New Module" cloudsdk in Android Studio
  3. copy bintray_upload_v1.gradle and pom_generator_v1.gradle into my project root directory.

When I build, it has error --

Plugin with id 'com.github.dcendents.android-maven' not found

Anyone has some procedures I could follow ?

I found a work around for the build error. Comment out following lines from cloudsdk build\

//apply from: '../pom_generator_v1.gradle'
//apply from: '../bintray_upload_v1.gradle'

Am I doing the right thing ??

Yeah, it’s fine to comment those out. You don’t actually need those two files at all, they’re just for publishing official releases of the SDK.

Thanks, the code is running now without problem (so far).

However, I still having issue trying to run CloudSDK in Sync mode (direct calling).
If I run below code, the call getStringVariable will return value correctly.

    Async.executeAsync(ParticleCloud.get(SparkLoginActivity.this), new Async.ApiWork<ParticleCloud, Object>() {
        @Override
        public Object callApi(ParticleCloud sparkCloud) throws ParticleCloudException, IOException {
            sparkCloud.logIn(email, password);              // Login server
            deviceList = sparkCloud.getDevices();           // Get device list from Cloud
            ParticleDevice mDevice = deviceList.get(0);
            try {msg = mDevice.getStringVariable("FWversion");}
            catch (IOException | ParticleCloudException | ParticleDevice.VariableDoesNotExistException
                    error)
            {};
            return -1;
        }

However, when I close this activity (finished) and pass the ParticleDevice mDevice into another Intent activity, when I call following, I did not able to have the variable return but a exception instead.

    ParticleDevice sprinkler = intent.getParcelableExtra("sprinkler");
    try {fwVersion = sprinkler.getStringVariable("FWversion");}
    catch (IOException | ParticleCloudException | ParticleDevice.VariableDoesNotExistException
            error)
    {};

I had tried pass ParticleCloud object back to parent activity using getParcelableExtra() in onActivityResult() but got build error.

Any suggestion is appreciated.

Finally, I managed to reused the async method to create multiple functions for each Spark access (Variables, Functions).

Now, I have another questions regarding how to

  1. Save and restore ParticleCloud login, so that when Apps restart, it can auto login.
  2. Connect to Core using SSID + WiFi network password (quick connect). Feature in Tinker Apps.

Does Spark-SDK provide above 2 features ? Or need to create my own by studying the Tinker Apps ?
Suggestions where and what to read through is appreciated :smile:

Hi,
I have modified the LoginActivity.java file of example_app by replacing “1f0034000747343232361234” with my Photon device ID.
But I still got a “Permission Denied” error.
Is there any other things that need to be modified to run this application?
Please teach.