Logging into the Particle Cloud in an Android app

Hello,

I’m trying to make a basic app that simply logs in to the particle cloud using my credentials and reads a list of devices associated with my account, however the login always fails. Is this how I should be logging in on the app? I’ve searched for examples using the code I found at https://docs.particle.io/reference/android/#android-device-setup-library but there doesn’t seem to be much around specifically using ParticleCloudSDK.getCloud().logIn.

This should be pretty basic, I’m not sure what I’m doing wrong.

    try {
        // Init the CloudSDK
        ParticleCloudSDK.init(MainActivity.this);
        ParticleCloudSDK.getCloud().logIn("*******", "******");
        Toaster.s(MainActivity.this, "Logged in!");
        // Now we're logged in, we want to read a list of devices
        getDeviceList();

    } catch (ParticleCloudException e) {
        Toaster.s(MainActivity.this, "FAILED TO LOGIN!");
   	}

private void getDeviceList(){

List<ParticleDevice> devices = null;
try {
    devices = ParticleCloudSDK.getCloud().getDevices();
    for (ParticleDevice device : devices) {
        if (device.getName().equals("myDevice")) {
            Toaster.s(MainActivity.this, "FOUND " + device.getName());
            break;
        }
        else
        {
            Toaster.s(MainActivity.this, "OTHER DEVICE " + device.getName());
        }
    }
} catch (ParticleCloudException e1) {
    e1.printStackTrace();
}

}

What result are you getting; does it print out "FAILED TO LOGIN!"?
Maybe try logging the ParticleCloudException instead to get more useful info.

Hey Ric,

Yes, it does print out “FAILLED TO LOGIN”, so an error is being caught.

I’m new to Android development, so maybe I’m not getting the correct error message, however when I pass toast messages of e.getMessage() or e.getBestMessage.tostring() I get:

io.particle.android.sdk.cloud.ParticleCloudException

I was hoping for something a little more descriptive.

Thanks.

Just to add some more details for this, I downloaded and compiled the example app https://github.com/spark/spark-sdk-android and when i try to login, it fails with a toaster message “permission denied” when using my particle account abd also on a second account I created for sanity checking. I’ve even programatically populated the login username and password in case I was all thumbs:

                final String email = "username";
                final String password = "password";

                final EditText textid = (EditText) findViewById(R.id.email);
                final EditText textpass = (EditText) findViewById(R.id.password);

                textid.setText(email);
                textpass.setText(password);

Something I’ve just noticed is ParticleCloud.get() is a depreciated function, maybe it doesn’t work now?

I am going through the same problems now. DId you ever find a way to get your photon to connect to android studio?

“Permission denied” is most likely because you forgot to change device id passed into getDevice method or you are trying to access device which does not belong to your account.

Just a question. Did you guys ever figure this out?I am having the EXACT same issue. I downloaded that app that you sent and got the same message. “Permission denied”

helloooo??? anyone?

Hey, just add your device id like mentioned above, and it should work. I had this issue first and then found that suggestion. Good luck :slight_smile:

1 Like