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 moved my Eclispe project to Android Studio, but it outputs a lot of deprecated errors when built. I tried some methods, but they don't work.
Try placing this at the top of the methods:
#SuppressWarnings("deprecation")
Example
#SuppressWarnings("deprecation")
public void testMethod(){
...
}
For a brief explaination go to this link:
https://stackoverflow.com/questions/7397996/what-is-suppresswarningsdeprecation-and-unused-in-android
Update:
It seems that there is also some known issues with deprecations. You might want to read this for more info:
stackoverflow.com/questions/26921774/how-to-avoid-deprecation-warnings-when-suppresswarningsdeprecation-doesnt
I am updating the app I am working on to work on Android 6.0.
In the beginning the app would crash, but updating the gradle file to use the newest versions of external libs (intercom and GCM services) did the trick and the app runs smoothly.
The only problem is that on startup a Toast message is displayed with the text: "Please specify next permissions in your manifest file: android.permission.WRITE_EXTERNAL_STORAGE".
The permission is of course written in the manifest file.
I am assuming this has something to do with the runtime permissions mechanism that Android 6.0 introduces (the message doesn't appear when running with older version of Android).
Another annoying little issue is that the toast message doesn't appear when running with a debugger (using Android Studio 1.4).
How can I know what is causing this Toast to appear? Has anyone else encountered this problem?
Thank you!
I have experienced this issue in my project as well, and it turns out that the toast is from ubertesters SDK, I decompiled the jar file and this is what I found.
package com.ubertesters.sdk.utility;
public class StringProvider {
public StringProvider() {
}
public static String addPermission() {
return "Please specify next permissions in your manifest file: ";
}
public static String installLatestVersion() {
return "Please, install the latest Ubertesters Hub version.";
}
public static String install() {
return "Install";
}
}
I will suggest you to exclude ubertesters SDK in your release product flavour and you won't see this toast in the release build.
Ubertesters has not updated its Android SDK for more than a year ... http://ubertesters.com/knowledge-base/android-sdk/
Ubertesters is constantly updating SDK for Android. The issue with handling permissions on Android 6.0 is successfully fixed in the next SDK version.
Please feel free to check and user our latest SDK available on the website http://ubertesters.com/knowledge-base/android-sdk/
Do anyone know how to integrate robolectric into android studio?
How to write sample test?
How to launch it?
I am working with android studio not to long, and I am too bad with gradle.
Searching the net didn't give me a result - I even could not launch official demo - https://github.com/robolectric/robolectric-samples . My android studio do not saw the test class.
Please give me simpliest step by step gide, thanks
Since robolectric runs in a JVM (i.e. not on a device or emulator), it is just a library and adding the test runner is all that's needed.
Make sure that the android SDK is later in the classpath than robolectric or junit - otherwise you'll get the stubbed methods from the android SDK.
#RunWith(RobolectricTestRunner.class)
public class MyActivityTest {
#Test
public void shouldHaveApplicationName() throws Exception {
String appName = new MyActivity().getResources().getString(R.string.app_name);
assertThat(appName, equalTo("MyActivity"));
}
}
See http://robolectric.org/quick-start/
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;