I have been following the docs for making an app in andriod studio and they state to copy a block of code into the onCreate method, hence my code looks as follows:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ParticleDeviceSetupLibrary.init(this);
findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ParticleDeviceSetupLibrary.startDeviceSetup(MainActivity.this,
MainActivity.class);
}
});
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//1
Async.executeAsync(ParticleCloudSDK.getCloud(),
new Async.ApiProcedure<ParticleCloud>() {
@Override
public Void callApi(ParticleCloud particleCloud)
throws ParticleCloudException, IOException {
//2
List<ParticleDevice> devices = particleCloud.getDevices();
//3
for (ParticleDevice particleDevice : devices) {
if ("myDevice".equals(particleDevice.getName())) {
try {
//4
int result = particleDevice
.callFunction("digitalwrite",
Arrays.asList("D7", "HIGH"));
//5
if (result == 1) {
Toast.makeText(MainActivity.this,
"Called a function on myDevice",
Toast.LENGTH_SHORT).show();
}
} catch (ParticleDevice
.FunctionDoesNotExistException e) {
//e.printStackTrace() to see whole stack trace
}
}
}
return null;
}
@Override
public void onFailure(ParticleCloudException exception) {
//e.printStackTrace() to see whole stack trace
}
});
}
});
}}
However although the first button to set up the photon works, the 2nd button does nothing when its clicked. Can anyone tell me if I misinterpreted the docs or if something has changed due to new version of Andriod Studio being released?