0

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?

  • What IDE (and version) are you using? BTW, you can get rid of `getBaseContext()`, as it is not needed here. – CommonsWare Jun 23 '17 at 14:56
  • Thank you, I use Android studio 2.3.3 – George Theodorakis Jun 23 '17 at 14:58
  • I just found this: https://stackoverflow.com/questions/27000896/media-projection-service-not-valid-in-call-to-getsystemservice that seems similar – George Theodorakis Jun 23 '17 at 15:02
  • I have run into this sort of problem before. However, it has always stemmed from either having too-old of a `compileSdkVersion` or a buggy Android Studio. Since new projects are working for you, neither of those are the culprit. What you might try is copying the entire project directory to a temporary location. In that copy, delete `build/`, `.gradle/`, `.idea/`, `*.iml`, `app/build/`, and `app/*.iml` (assuming that you have a single module named `app`). Then, import that copy into Android Studio and see if you get the error. – CommonsWare Jun 23 '17 at 15:09
  • @CommonsWare no, unfortunately that did not work either – George Theodorakis Jun 26 '17 at 07:43

1 Answers1

1

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