2

As a new Calendar class was introduced in API 24 in package android.icu.util with more calendars and better localization. I'm wondering if there is a way to use this Calendar for Android API >=24, and old deprecated Calendar from java.util package for Android API <24.

There is a little reason to set minSdkVersion = 24. Also I cannot assign android.icu.util.Calendar to java.util.Calendar field depending on API level. Have anyone solved this? Or just use old calendar and wait untill market drop of old devices?

Oleksandr Albul
  • 1,611
  • 1
  • 23
  • 31
  • 1
    Why not take the step and add [ThreeTenABP](https://github.com/JakeWharton/ThreeTenABP) to your Android project so you can use [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/)? It’s so much nicer to work with. Said without knowing much about `android.icu.util.Calendar`, but `java.util.Calendar` at least is long outdated and poorly designed, and I don’t get a much better impression of the `icu` one. – Ole V.V. Mar 12 '18 at 07:45
  • What would the point be? Should your app exploit some ICU feature/s when running on API level 24 and above and thereby present functionality to the user that isn’t available when it runs on API level 23 and lower? – Ole V.V. Mar 12 '18 at 08:22
  • 1
    Or use my lib [Time4A](https://github.com/MenoData/Time4A) which offers good internationalization (like ICU4J) AND more calendars in better quality AND compatibility even with old API-levels. – Meno Hochschild Mar 12 '18 at 11:22
  • @MenoHochschild I haven't find any mention of a license, and it is quite strange. – Oleksandr Albul Mar 12 '18 at 15:58
  • @OleV.V. Maybe it is a good point. But for what reason android devs have implemented icu.Calendar? The reasons why I do not want to migrate to ThreeTen: 1. Do not want bloat apk 2. Want to use Android timezone, and not the latest from IANA. I have another app with Jodatime wich gives me lots of pain because of it. – Oleksandr Albul Mar 12 '18 at 16:01
  • About Time4A-licence (a derivate from Time4J), see also [this issue](https://github.com/MenoData/Time4J/issues/621), Oh, it seems I have forgotten to officially add an extra licence file to the project, sorry for confusion. And about tz-data, the IANA-tzdb is embedded and the default but the platform tz-data can be used, too (although I actually think this could be done in a more comfortable way, for example per initialization parameter). – Meno Hochschild Mar 12 '18 at 18:34

1 Answers1

0

For using icu.util.Calendar in pre Android 24 you should add the library from IBM into your gradle :

implementation group: 'com.ibm.icu', name: 'icu4j', version: '69.1'

So instead of using android.icu.util.Calendar you should use com.ibm.icu.util.Calendar.

This answer help me a lot.

IBM calendar maven : https://mvnrepository.com/artifact/com.ibm.icu/icu4j

Nishuthan S
  • 1,538
  • 3
  • 12
  • 30