Код: Выделить всё
SharedPreferences.Editor editor = getSharedPreferences("MY_PREFS_NAME", MODE_PRIVATE).edit();
editor.putString("temp", wristSkinTempC);
editor.putString("tempF", wristSkinTempF);
editor.apply();
Вот мой код усложнения
Код: Выделить всё
private fun createAppShortcutComplication(): ComplicationData {
val prefs = getSharedPreferences("MY_PREFS_NAME", MODE_PRIVATE)
val tempC = prefs.getString("temp", "") //"No name defined" is the default value.
val intent = Intent(this, MainActivity::class.java).apply {
component = ComponentName(this@CustomComplicationC, MainActivity::class.java)
}
val pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
return ShortTextComplicationData.Builder(
text = PlainComplicationText.Builder(text = tempC.toString()).build(),
contentDescription = PlainComplicationText
.Builder(text = "Short Text version of Number.").build(),
).setMonochromaticImage(
MonochromaticImage.Builder(
image = Icon.createWithResource(this, R.drawable.iconforbody),
).build(),
).setTapAction(pendingIntent)
.build()
}
Код: Выделить всё
Подробнее здесь: https://stackoverflow.com/questions/780 ... test-value