Detect Led Notifications Android Studio

4

I have a simple doubt, I am programming notifications, and I realize that when I involve the line of code:

.setLights(Color.GREEN, 3000, 3000)

It appears errors in cell phones that do not have the notification LED (such as cell phones with android 4.1.1), so I was wondering if there is any method to know if the cell where the application is running detects whether or not it has this famous Notification LED to indicate: If you have the LED then do the line of code:

.setLights(Color.GREEN, 3000, 3000)

If you do not have the LED then do not do that line of code

    
asked by Luis Olazo 27.07.2018 в 08:18
source

1 answer

1

How to detect if the device supports displaying colors using the LED.

Currently (Android 8.1) there is no API to detect whether the device can show colors by LED when we show notifications.

How to detect if the device supports vibrate.

If your device supports vibration, you can detect it using the Vibrator class:

Vibrator mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
        boolean hasVibrator = mVibrator != null && mVibrator.hasVibrator();
        if(hasVibrator) {
           // Muestra notificación with vibration.
        }else{
           //Muestra notificación sin vibración.
        }

Currently it seems to me that the latest operating systems do not require permission, but I advise you to add android:required="false" so that your application in the Play Store does not filter your application for devices that do not support vibration.

 <uses-permission android:name="android.permission.VIBRATE" android:required="false"/>
    
answered by 28.07.2018 в 01:27