I'm buliding a watch face and want to display the remaining time on the timer.
I've been looking for ways to access (presumably) "com.google.android.deskclock" for the timer data, but have not found anything on the net.
Thank you for your help.
There's no official API for this, but because the system Clock app exposes this value via a complication, you can access it that way.
Start by specifying the timer complication as a default:
setDefaultComplicationProvider(myComplicationId,
new ComponentName("com.google.android.deskclock",
"com.google.android.deskclock.complications.TimerProviderService"),
ComplicationData.TYPE_SHORT_TEXT);
If your watch face already supports complications, you could just feed this provider into that logic. Otherwise - if you want to do something else with the timer value - you'll need to extract it from the ComplicationData
. So, in your WatchFaceService.Engine
subclass:
@Override
public void onComplicationDataUpdate(int complicationId, ComplicationData complicationData) {
super.onComplicationDataUpdate(watchFaceComplicationId, data);
if (complicationId == myComplicationId) {
// This is the timer complication
CharSequence timerValue = complicationData.getShortText()
.getText(getBaseContext(), System.currentTimeMillis());
}
}
This gives you the current timerValue
to do whatever you'd like with.
A couple of caveats to this approach: