I just downloaded the spark-sdk-android zip and open & build with Android Studio. I also checked the doc and it indicates it requires
sparkCloud.logIn
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 ?
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.
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.
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
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.
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
Save and restore ParticleCloud login, so that when Apps restart, it can auto login.
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
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.