Vibrate and Sound defaults on notification

后端 未结 9 1158
天涯浪人
天涯浪人 2020-12-04 07:37

I\'m trying to get a default vibrate and sound alert when my notification comes in, but so far no luck. I imagine it\'s something to do with the way I set the defaults, but

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-04 08:23

    Some dummy codes might help you.

       private static NotificationCompat.Builder buildNotificationCommon(Context _context, .....) {
                NotificationCompat.Builder builder = new NotificationCompat.Builder(_context)
                .setWhen(System.currentTimeMillis()).......;
         //Vibration
            builder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });
    
         //LED
            builder.setLights(Color.RED, 3000, 3000);
    
         //Ton
            builder.setSound(Uri.parse("uri://sadfasdfasdf.mp3"));
    
        return builder;
       }
    

    Add below permission for Vibration in AndroidManifest.xml file

    
    

提交回复
热议问题