private PendingIntent getChangeTempIntent(int value) {
Intent intent = new Intent(ACTION_CHANGE_TEMP);
intent.setClass(context, MyBroadcastReceiver.class);
intent.putExtra(EXTRA_TEMP_VALUE, value);
return PendingIntent.getBroadcast(getContext(), sReqCode++, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
I think it's not really needed to increase it all the time, as the request might interfere with other kinds of codes.
I think it's easier to split it to inc&dec. For example:
private PendingIntent getChangeTempIntent(int value, boolean hasIncreased) {
Intent intent = new Intent(ACTION_CHANGE_TEMP);
intent.setClass(context, MyBroadcastReceiver.class);
intent.putExtra(EXTRA_TEMP_VALUE, value);
return PendingIntent.getBroadcast(getContext(), hasIncreased ? 0 : 1, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
SliceAction tempUp = new SliceAction(getChangeTempIntent(sTemperature + 1, true),
IconCompat.createWithResource(context, R.drawable.ic_temp_up).toIcon(),
"Increase temperature");
SliceAction tempDown = new SliceAction(getChangeTempIntent(sTemperature - 1, false),
IconCompat.createWithResource(context, R.drawable.ic_temp_down).toIcon(),
"Decrease temperature");
Seems to work fine...