getSystemService(Context.FINGERPRINT_SERVICE) error - android

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

Related

What is a reason behind this "OnChecksumsReadyListener.onChecksumsReady" AbstractMethodError?

I received this exception on release build with Android 12.
exception.class.missing._Unknown_: java.lang.AbstractMethodError abstract method "void android.content.pm.PackageManager$OnChecksumsReadyListener.onChecksumsReady(java.util.List)"
at android.app.ApplicationPackageManager$2.onChecksumsReady (ApplicationPackageManager.java:969)
at android.content.pm.IOnChecksumsReadyListener$Stub.onTransact (IOnChecksumsReadyListener.java:87)
at android.os.Binder.execTransactInternal (Binder.java:1184)
at android.os.Binder.execTransact (Binder.java:1143)
Anyone knows reason behind this? or How to fix this issue!?
Related to the common AbstractMethodError, you can get more information from this topic: https://stackoverflow.com/a/17970129/19303683
In my case, i get this problem when i try to downgrade target sdk to 30. My solution is:
Find all dependencies related to work-runtime (such as firebase ads) using Gradlew and downgrade them.
Remove this code from gradle if you have:
configurations.all {resolutionStrategy { force
'androidx.work:work-runtime:2.6.0' }}

How to resolve "Obsolete custom lint check" for my custom IssueRegistry written in Kotlin and make it work (Android)

I am trying to implement custom lint checks (using Kotlin). I have set up a module for my custom checks and added classes to test my first lew lint check, mostly following these two tutorials here and here.
So I now have a module, I have a custom IssueRegistry, I've created an issue and a Detector class for it. So far it seems complete. I've added a test to check if my lint check works and it looks alright.
I have added my module to the project by referencing it in settings.gradle like this: include ':app', ':somemodule', ':mylintmodule'
Now if I run the linter using ./gradlew lint I get a lint result file telling me this:
Lint found an issue registry (com.myproject.mylintmodule) which requires a newer API level. That means that the custom lint checks are intended for a newer lint version; please upgrade
Lint can be extended with "custom checks": additional checks implemented by developers and libraries to for example enforce specific API usages required by a library or a company coding style guideline.
The Lint APIs are not yet stable, so these checks may either cause a performance degradation, or stop working, or provide wrong results.
This warning flags custom lint checks that are found to be using obsolete APIs and will need to be updated to run in the current lint environment.
It may also flag issues found to be using a newer version of the API, meaning that you need to use a newer version of lint (or Android Studio or Gradle plugin etc) to work with these checks.
To suppress this error, use the issue id "ObsoleteLintCustomCheck" as explained in the Suppressing Warnings and Errors section.
So it tells me that I am using a newer API verion in my custom lint check, right? This is my custom IssueRegistry (minus some parts not relevant for this problem):
class MyCustomIssueRegistry : IssueRegistry() {
override val issues: List<Issue>
get() = listOf(ISSUE_NAMING_PATTERN)
override val api: Int = com.android.tools.lint.detector.api.CURRENT_API
override val minApi: Int = 1
}
From googling this problem and finding this issue I figured I have to override and set the right API version (and maybe the min API?) by overriding these properties like I did above (this version is my last attempt, directly taken from that issue).
So this property can be set to values between -1 and 5, meaning this (taken right out of the lint.detector.api class):
/** Describes the given API level */
fun describeApi(api: Int): String {
return when (api) {
5 -> "3.5+" // 3.5.0-alpha07
4 -> "3.4" // 3.4.0-alpha03
3 -> "3.3" // 3.3.0-alpha12
2 -> "3.2" // 3.2.0-alpha07
1 -> "3.1" // Initial; 3.1.0-alpha4
0 -> "3.0 and older"
-1 -> "Not specified"
else -> "Future: $api"
}
I have tried all of them, plus the one above adding a minApi override too, and I keep getting the exact same result for each of them.
Also I am unable to locate what other API version this is compared with. Is there a place where this is set for the regular linter in an Android project?
It's also unclear to me what I have to do to make sure my changes got applied - is it enough to change some code, then run lint, or do I have to compile the project first, or build & clean?
Following the tutorials, I added my custom lint check by adding this to the app's build.gradle: lintChecks project(":mylintmodule")
Is that even right? The API issue on my registry class shows up no matter if my lint check is referenced (and hopefully used) like that or not. I have also tried the other method described in the first tutorial, adding this task to the linter module build.gradle:
defaultTasks 'assemble'
task copyLintJar(type: Copy) {
description = 'Copies the lint jar file into the {user.home}/.android/lint folder.'
from('build/libs/')
into(System.getProperty("user.home") + '/.android/lint')
include("*.jar")
}
// Runs the copyLintJar task after build has completed.
build.finalizedBy(copyLintJar)
But since I can't figure out how to see if my custom checks are actually run, I don't know if that works as intended either.
So how do I get this warning resolved (since I interpret the text as "As long as the versions don't match I will not try to run your lint check"), and how can I make sure my lint check is actually run by the linter?

AndroidStudio disable "Expected resource of type string"

I've just tried to generate signed apk for one of my projects (I already did this before), but (maybe since updating Android Studio) I'm getting
Error:Error: Expected resource of type string [ResourceType]
This is because I'm using Butterknife's #BindString, that is generated into something like that
target.settings = res.getString(2131230792);
How can I make studio not detect this as error? I've tried searching in settings, but without success.
Answer to this is: disable lint rule in your build.gradle
android {
lintOptions {
disable "ResourceType"
}
}
Edit:
This may happen particularly when migrating from Eclipse to Android Studio.
This is reported on the GitHub project.
It will be fixed in the next version of ButterKnife.
The workaround is indicated there, and is to add a lint.xml file on the app module with the following content to ignore that errors on *$$ViewBinder classes (the ones that ButterKnife generates):
<issue id="ResourceType">
<!-- Remove this when this is fixed: https://github.com/JakeWharton/butterknife/issues/338 -->
<ignore path="**/*$$ViewBinder.java" />
</issue>
Maybe a better solution is to temporary disable error/warning by using #SuppressLint("ResourceType") just before the method definition.
I has a similar problem. with a getString method. Turned out i was trying to get the string value not from strings.xml but from ids.xml, because i was getting it with getString(R.id.MYSTRING), when it should be R.string.MYSTRING
this is for some Views by same id and u try to change some property for one of them.
When try to generate apk android find some confilict about resours id
To solve that
better way find the code and try solve that from another way to your purpose
GoodLuck

Tool to Check if code contains higher API calls than minimum level

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

Lint and old API level warning

I compile against Android 4.2 (API 17), in my Manifest I have:
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"/>
In code I use:
String first = sdf.format(new Date(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).firstInstallTime));
Field firstInstallTime was introduced in API 9.
Lint does not warn me, i.e. that this field is not valid in API 8. What am I missing, how should one detect this?
If I compile against Android 2.2 (API 8), I find the error and a bunch of extra errors due to new features used (> API 8) and the project won't compile.
(I'm aware of handling such things in runtime with for example Build.VERSION.SDK_INT)
What's the best way of working?
Why is lint not working?
Thanks!
This answer may be late but You should check your lint preferences
Right click on project -> Properties -> Android Lint Preferences
then search for min in the searchbox and select "UsesMinSDKAttributes"
Finally select "Include all" button. Hopefully the check had just been surpressed (Something I've had to do just to fix a silly lint error)
Good luck.
If it is intoduced in api level9 then try this.
< uses-sdk android:minSdkVersion="9" android:targetSdkVersion="10"/>
Probably it will works when the https://code.google.com/p/android/issues/detail?id=56427 will be solved

Categories

Resources