1. 程式人生 > >系統震動,響鈴,指示燈

系統震動,響鈴,指示燈


            ScreenUtils.sound();     
            ScreenUtils.light(lightDbSet.getT() && ScreenUtils.isForeground(getActivity()))   
            ScreenUtils.shake();
       
public static void sound() {
        NotificationManager manager =
                (NotificationManager) App.getInstance().getCurActivity().getSystemService(NOTIFICATION_SERVICE);
        Notification notification = new Notification();
        notification.defaults = Notification.DEFAULT_SOUND;
        int soundId = new Random(System.currentTimeMillis()).nextInt(Integer.MAX_VALUE);
        if (manager == null) {
            return;
        }
        manager.notify(soundId, notification);
    }

    public static void light(boolean isNotify) {
        NotificationManager lightManager =
                (NotificationManager) App.getInstance().getCurActivity().getSystemService(NOTIFICATION_SERVICE);
        if (lightManager == null) {
            return;
        }
        if (isNotify) {
            Notification notification = new Notification();
            notification.ledARGB = Color.GREEN;//RED
            notification.ledOnMS = 100;
            notification.ledOffMS = 100;
            notification.flags = Notification.FLAG_SHOW_LIGHTS;
            lightManager.notify(1, notification);
        } else {
            lightManager.cancel(1);
        }
    }

    public static void shake() {
        Vibrator vibrator = (Vibrator) App.getInstance().getCurActivity().getSystemService(VIBRATOR_SERVICE);
        if (vibrator != null) {
            vibrator.vibrate(1000);
        }
    }