I know how to get the API level, android.os.Build.VERSION.SDK_INT, but there are also several revisions of each level release, e.g. for 2.1 there's rev 1 and 2. How do I determine the revision of a build?
The reason i'd like to know this is that I have a workaround for a bug in Android 2.1 (and 2.2), and this workaround will break the moment the corresponding bug is fixed. So right now i'm in the odd position of hoping that the bug won't be fixed (at least not until I can find an answer to above question).
I'm not sure which revision you're reffering to, but the revision you set in your manifest file you can get with the following code:
paramContext is your Context object
PackageManager localPackageManager = paramContext.getPackageManager();
PackageInfo localPackageInfo = localPackageManager.getPackageInfo(paramContext.getPackageName(), 0);
String version = localPackageInfo.versionName;
If you want to extract the build version, use this code:
String version = Build.VERSION.RELEASE;
Related
I just updated the Android Q SDK to revision 2 in android studio and now I get an error with getting values from a hashmap
it is HashMap<String,String> and this code was fine until I did the update in android studio to Q revision 2.
This is where my HashMap comes from
val map = HashMap<String,String>()
map["owner"] = shipment.owner
map["current"] = signedInUser
shipmentOwnedLiveData.postValue(map)
I found a question similar to this but non-android related and its a few years old
Anyone know what the issue is or how to fix it?
Edit:
Seems like it also broke ArrayLists too as calling .contains or .remove on a collection also throws an ambiguity error.
it looks like there are duplicate methods for all of these
Edit 2:
Looks like I am not the only person with this issue
https://issuetracker.google.com/issues/139041608#comment3
It was a bug with the latest Android SDK 29 release until Google rolled back the update. See https://issuetracker.google.com/issues/139041608.
If you were unfortunate enough to install platforms;android-29 revision 2 before they rolled it back, you'll have to downgrade back to revision 1. You can do this by first uninstalling the package using the $ANDROID_HOME/tools/bin/sdkmanager tool.
sdkmanager --uninstall "platforms;android-29"
Then remove revision 2 from the cache by removing the "platforms;android-29" element containing <major>2</major> from $HOME/.android/cache/sdkbin-1_b735609c-repository2-1_xml:
<remotePackage path="platforms;android-29">
<!--Generated from bid:5747142, branch:qt-release-->
<type-details xsi:type="sdk:platformDetailsType">
<api-level>29</api-level>
<codename></codename>
<layoutlib api="15"/>
</type-details>
<revision>
<major>2</major>
</revision>
<display-name>Android SDK Platform 29</display-name>
<uses-license ref="android-sdk-license"/>
<channelRef ref="channel-0"/>
<archives>
<archive>
<!--Built on: Tue Jul 23 11:56:59 2019.-->
<complete>
<size>78259143</size>
<checksum>c8b1361cc03309a8113de92f93471524fa0c36f7</checksum>
<url>platform-29_r02.zip</url>
</complete>
</archive>
</archives>
</remotePackage>
Keep the other "platforms;android-29" element with <major>1</major> and then re-install the package:
sdkmanager --install "platforms;android-29"
I ran into the same problem and found a workaround for HashMap and ArrayList:
You can instantiate the map as
val map: MutableMap<String, String> = HashMap()
For ArrayList
val list: MutableList<String> = ArrayList()
As per the bug report in the issue tracker, google has reverted r2 back to r1
API 29 r2 has been rolled back from Studio SDK Manager for now until
the root cause is identified and fixed.
So just uninstall/reinstall Q from the adk manager and you should be back on r1
I ran into the same problem, For now as a workaround I am using the Kotlin extension function getOrElse, which allows you to provide a default value if the map does not contain the given key.
Interesting bug I found while regression test of android app.
android.R.string.no is the same as android.R.string.cancel, but, exact No is android.R.string.gpsVerifNo. Why so?
UPD: android.R.string.gpsVerifNo not public or not exist in all sdk versions
I use the following code:
FingerprintManager fingerprintManager = (FingerprintManager) getBaseContext().getSystemService(Context.FINGERPRINT_SERVICE);
Context.FINGERPRINT_SERVICE gets underlined in red like an error and it suggests:
Must be one of: Context.POWER_SERVICE, Context.WINDOW_SERVICE, Context.LAYOUT_INFLATER_SERVICE, Context.ACCOUNT_SERVICE, Context.ACTIVITY_SERVICE, Context.ALARM_SERVICE, Context.NOTIFICATION_SERVICE, Context.ACCESSIBILITY_SERVICE, android.content.Context.CAPTIONING_SERVICE, Context.KEYGUARD_SERVICE, Context.LOCATION_SERVICE, Context.SEARCH_SERVICE, Context.SENSOR_SERVICE, android.content.Context.STORAGE_SERVICE, Context.WALLPAPER_SERVICE, Context.VIBRATOR_SERVICE, Context.CONNECTIVITY_SERVICE, android.content.Context.NETWORK_STATS_SERVICE, Context.WIFI_SERVICE, android.content.Context.WIFI_P2P_SERVICE, android.content.Context.NSD_SERVICE, Context.AUDIO_SERVICE, android.content.Context.FINGERPRINT_SERVICE, android.content.Context.MEDIA_ROUTER_SERVICE, Context.TELEPHONY_SERVICE, android.content.Context.TELEPHONY_SUBSCRIPTION_SERVICE, android.content.Context.CARRIER_CONFIG_SERVICE, android.content.Context.TELECOM_SERVICE, Context.CLIPBOARD_SERVICE, Context.INPUT_METHOD_SERVICE, android.content.Context.TEXT_SERVICES_MANAGER_SERVICE, android.content.Context.APPWIDGET_SERVICE, Context.DROPBOX_SERVICE, Context.DEVICE_POLICY_SERVICE, Context.UI_MODE_SERVICE, android.content.Context.DOWNLOAD_SERVICE, android.content.Context.NFC_SERVICE, android.content.Context.BLUETOOTH_SERVICE, android.content.Context.USB_SERVICE, android.content.Context.LAUNCHER_APPS_SERVICE, android.content.Context.INPUT_SERVICE, android.content.Context.DISPLAY_SERVICE, android.content.Context.USER_SERVICE, android.content.Context.RESTRICTIONS_SERVICE, android.content.Context.APP_OPS_SERVICE, android.content.Context.CAMERA_SERVICE, android.content.Context.PRINT_SERVICE, android.content.Context.CONSUMER_IR_SERVICE, android.content.Context.TV_INPUT_SERVICE, android.content.Context.USAGE_STATS_SERVICE, android.content.Context.MEDIA_SESSION_SERVICE, android.content.Context.BATTERY_SERVICE, android.content.Context.JOB_SCHEDULER_SERVICE, android.content.Context.MEDIA_PROJECTION_SERVICE, android.content.Context.MIDI_SERVICE, android.content.Context.HARDWARE_PROPERTIES_SERVICE, android.content.Context.SHORTCUT_SERVICE, android.content.Context.SYSTEM_HEALTH_SERVICE
my compileSdkVersion is 24.
Although I have this error, my app runs and works fine.
When I start a new project, the same code has no warnings at all.
I know that it is not a big problem, but it annoys me.
Suggestions plz?
I solved it..
I had a couple of older projects as libraries in my project and their target sdks and compiled sdks in their manifests and gradle files were lower than 24. Although I was allowed to build this thing before, I had a few problems that were fixed once I updated everything.
I reached to this solution after I fixed a problem similar to All com.android.support libraries must use the exact same version specification
I am working with a large project, which has a minimum API level:16. however, I came across API usages that are above API level 16.
Is there any tool in Android studio or elsewhere, other than testing with a device, to check if the code doesn't violate the minimum required API level or better point it out like an error etc.?
Thank you.
The IDE will use the minimum android SDK, thus you will not get compile errors. If you there are classes in SDK 14 which are moved in sdk 16, yet you are using the imports from SDK 14, it will give a standard compile error.
So no, not that I am aware of.
You can use something like this:
public static boolean supports(final int version) {
return Build.VERSION.SDK_INT >= version;
}
Like this,
if (supports(Build.VERSION_CODES.HONEYCOMB)) {
// do something HONEYCOMB+ compatible here
}
More codes here,
http://developer.android.com/reference/android/os/Build.VERSION_CODES.html
Can I use Android version code constants with older Android runtimes? For instance,
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.HONEYCOMB) ...
would this run without crash on old devices running Android operating system before HONEYCOMB when this constant has been first defined? Assuming we compile it with recent enough SDK?
Yes, this will work.
The reason for this is that android.os.Build.VERSION_CODES.HONEYCOMB is an int. android.os.Build.VERSION_CODES.HONEYCOMB is just an alias (the int equals 11) for 11, as can be seen in an IDE such as Eclipse:
int android.os.Build.VERSION_CODES.HONEYCOMB = 11 [0xb]
So this will work as it'll just check if the android.os.Build.VERSION.SDK_INT is greater than or equal to 11.
Yes you can. It works because the int values are static final. The compiler will inline them into the bytecode at compile time. No symbol import is required at runtime.