Skip Login screen on Android Setup Library with organization

I need to be able to skip the login screen on the android app. I’m following the documentation and this is what I’m doing right now:

  1. I’m logging the user in to my server with my credentials.

  2. In my server, I’m creating a shadow customer with Particle and sending the access token to my android client.

  3. In my android app, I’m setting the access token using ParticleCloudSDK.getCloud().setAccessToken("ACCESS_TOKEN_HERE", new Date(14614569517535L));

  4. I’m checking ParticleCloudSDK.getCloud().isLoggedIn() and the result is false.

  5. Then, when I start ParticleDeviceSetupLibrary.startDeviceSetup(this); the app shows the Particle Login screen, and not directly the setup wifi screen I want to show.

I’m stuck here. I appreciate your help.

@ido @jensck

Version 0.3.6 of the device setup lib should fix this.

1 Like

Awesome! This is great news.

I’m still getting false when calling ParticleCloudSDK.getCloud().isLoggedIn() after setting the access token.

It now skips the login screen, but when clicking the READY button, it crashes and throws the following error in the stack:

03-15 23:31:05.772 13596-13596/my.sample.app E/AndroidRuntime: FATAL EXCEPTION: main
  Process: my.sample.app, PID: 13596
  java.lang.RuntimeException: Unable to start activity ComponentInfo{my.sample.app/io.particle.android.sdk.devicesetup.ui.DiscoverDeviceActivity}: java.lang.IllegalArgumentException: Null value for 'username'
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
      at android.app.ActivityThread.access$800(ActivityThread.java:151)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
      at android.os.Handler.dispatchMessage(Handler.java:102)
      at android.os.Looper.loop(Looper.java:135)
      at android.app.ActivityThread.main(ActivityThread.java:5254)
      at java.lang.reflect.Method.invoke(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:372)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
   Caused by: java.lang.IllegalArgumentException: Null value for 'username'
      at com.squareup.phrase.Phrase.put(Phrase.java:126)
      at io.particle.android.sdk.devicesetup.ui.DiscoverDeviceActivity.onCreate(DiscoverDeviceActivity.java:123)
      at android.app.Activity.performCreate(Activity.java:5990)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387) 
      at android.app.ActivityThread.access$800(ActivityThread.java:151) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303) 
      at android.os.Handler.dispatchMessage(Handler.java:102) 
      at android.os.Looper.loop(Looper.java:135) 
      at android.app.ActivityThread.main(ActivityThread.java:5254) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:372) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698) 

I suspect it has to do with the fact that the customer I registered for my organization from my back-end doesn’t show on dashboard.particle.com. Actually I followed the docs and I noticed that when you create a customer you never specify a product, although the customers in the dashboard are grouped by product, not by organization. This is the exmple I followed:

curl -X POST -u "client-id-goes-here:client-secret-goes-here" -d email=abu@agrabahmonkeys.com \
-d no_password=true https://api.particle.io/v1/orgs/particle/customers

Thanks

@javo I posted a hot-fix just now – try version 0.3.6.1 of the device setup lib.

I’m running into this same Null value for ‘username’ issue… where is 0.3.6.1 version of the setup lib? I only see 0.3.6 on github ?!?

as a workaround I was able to use java reflection api to set the ParticleCloud.particleUser field… ugly but seems to work…

        String tokenString = ...;
        Date expirationDate = ...;

        ParticleCloud spark = ParticleCloudSDK.getCloud();
        try {
            Field particleUserField = spark.getClass().getDeclaredField("user");
            particleUserField.setAccessible(true);
            ParticleUser particleUser = ParticleUser.fromNewCredentials("some@email.com", "no_password");
            particleUserField.set(spark, particleUser);

            spark.setAccessToken(tokenString, expirationDate);
            ParticleDeviceSetupLibrary.getInstance().startDeviceSetup(this);
        } catch (Exception e) {
            alert(e);
        }

I tried using 0.3.6.1 and while my gradle did successfully find it I am still having the same 'Null value for ‘username’ issue