Vibrate and Sound defaults on notification

后端 未结 9 1161
天涯浪人
天涯浪人 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:26

    I m using the followung code and its working fine for me .

    private void sendNotification(String msg) {
        Log.d(TAG, "Preparing to send notification...: " + msg);
        mNotificationManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
    
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, MainActivity.class), 0);
    
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
                this).setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("GCM Notification")
                .setAutoCancel(true)
                .setDefaults(Notification.DEFAULT_ALL)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
                .setContentText(msg);
    
        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
        Log.d(TAG, "Notification sent successfully.");
    }
    

提交回复
热议问题