When creating a library i'm finding tasks that are simple to do with newer versions of Android but require workarounds on older versions.
The workarounds can vary in their complexity.
For example i want to include some images in a class, i want to include those images as Base64 encoded strings.
I'm talking about 8 images varying in size from under 1KB to just over 5KBs.
Since Android API level 8, the API has a built in Base64 utility class which i can use:
Simple and quick - the class works and is complete.
Versions of Android API levels prior to 8 do not have that Base64 class.
The possible workarounds are:
Do not use the API level 8 Base 64 class and either:
I know the majority of you will say that it's important for a B4A library to support the same Android versions that B4A itself supports - and i agree.
But what's the point in having new native Android SDK classes to make development more straightforward if you cannot use them because you must support older versions of the API?
Martin.
The workarounds can vary in their complexity.
For example i want to include some images in a class, i want to include those images as Base64 encoded strings.
I'm talking about 8 images varying in size from under 1KB to just over 5KBs.
Since Android API level 8, the API has a built in Base64 utility class which i can use:
B4X:
byte[] decodedBitmapBytes = Base64.decode(encodedBitmapString, Base64.DEFAULT);
return BitmapFactory.decodeByteArray(decodedBitmapBytes, 0, decodedBitmapBytes.length);
Simple and quick - the class works and is complete.
Versions of Android API levels prior to 8 do not have that Base64 class.
The possible workarounds are:
Do not use the API level 8 Base 64 class and either:
- Make it a requirement of my library that the developer includes the B4A StringUtils library in their project - my library would expect StringUtils to be available and not work if it was not included in the project.
- Find a (free) third party Base64 class and include that in my library.
This can be done but the third party class is a massive class that has many methods and features.
I require just a 'decode Base64 String to Byte Array' method. - Do not Base64 encode these images and instead rely upon the developer including them in their project in the project's res/drawable folder and making sure they have their read-only property checked.
Can my library package access the resources of the B4A application package? The workaround is getting complex and is time consuming.
I know the majority of you will say that it's important for a B4A library to support the same Android versions that B4A itself supports - and i agree.
But what's the point in having new native Android SDK classes to make development more straightforward if you cannot use them because you must support older versions of the API?
Martin.