dear community ,
i am using android sdk , and have created an app to recive published events from photon device ,i am able to recive events but recived data is not updating in my android main UI . i am attaching the main code snippet .
in code ONSuccess section is executing only once .
please help . if need more info please ask …
TextView txtcurr,txttemp,txtmode,valuetemp,valuecurr,valuemode,valuedist,txtdist;
long subscriptionId;
GaugeView socgauge;
String variable="-1,-1,-1,-1,-1";
DeluxeSpeedView raySpeedometer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(activity_fullscreen);
ParticleCloudSDK.init(FullscreenActivity.this);
raySpeedometer = (DeluxeSpeedView) findViewById(R.id.DeluxeSpeedView);
raySpeedometer.setWithEffects(false); //def : true
raySpeedometer.setSpeedBackgroundColor(Color.BLACK);
socgauge= (GaugeView) findViewById(R.id.gauge);
txtcurr = (TextView) findViewById(R.id.txtcurr);
txtmode = (TextView) findViewById(R.id.txtmode);
txttemp = (TextView) findViewById(R.id.txttemp);
txtdist = (TextView) findViewById(R.id.txtdist);
valuecurr = (TextView) findViewById(R.id.valuecurr);
valuemode = (TextView) findViewById(R.id.valuemode);
valuetemp = (TextView) findViewById(R.id.valuetemp);
valuedist = (TextView) findViewById(R.id.valuedist);
Typeface lcdTypeface = Typeface.createFromAsset(getAssets(), "fonts/digital7.ttf");
txtcurr.setTypeface(lcdTypeface);
txtmode.setTypeface(lcdTypeface);
txttemp.setTypeface(lcdTypeface);
valuecurr.setTypeface(lcdTypeface);
valuetemp.setTypeface(lcdTypeface);
valuemode.setTypeface(lcdTypeface);
txtdist.setTypeface(lcdTypeface);
valuedist.setTypeface(lcdTypeface);
socgauge.setValue(0);
valuedist.setText("0");
valuecurr.setText("0");
valuetemp.setText("0");
valuemode.setText("0");
raySpeedometer.speedTo(0);
Async.executeAsync(ParticleCloudSDK.getCloud(), new Async.ApiWork<ParticleCloud, String>() {
@Override
public String callApi(ParticleCloud ParticleCloud) throws ParticleCloudException, IOException {
subscriptionId = ParticleCloudSDK.getCloud().subscribeToDeviceEvents("temp", "3d001047343432313xx",
new ParticleEventHandler() {
public void onEvent(String eventName, ParticleEvent event) {
variable = event.dataPayload;
Log.i("tag", "Received event with payload: " + variable + " " + eventName);
}
public void onEventError(Exception e) {
Log.e("some tag", "Event error: ", e);
variable = "-1,-1,-1,-1,-1";
}
}
);
return variable;
}
@Override
public void onSuccess(String i) {
String[] datavalues = i.split(",");
socgauge.setValue(Float.parseFloat(datavalues[0]));
valuedist.setText("22");
valuecurr.setText(datavalues[2]);
valuetemp.setText(datavalues[3]);
valuemode.setText(datavalues[4]);
raySpeedometer.speedTo(0);
Log.i("tag", "SOC:" + datavalues[0]);
Log.i("tag", "volt:" + datavalues[1]);
Log.i("tag", "curr:" + datavalues[2]);
Log.i("tag", "temp:" + datavalues[3]);
Log.i("tag", "mode:" + datavalues[4]);
}
@Override
public void onFailure(ParticleCloudException e) {
e.printStackTrace();
Log.e("some tag","error", e);
}
});
}