1

Je fais la prochaine pour appeler une notification sur android studio quand j'envoie un message hors de l'application, seulement montrer l'icône et le texte, mais ne joue pas le son ou la vibration quand je suis à l'intérieur de l'application, jouer du son et vibrer. Toute aide? Je le manifeste Méthode de notification d'exposition:push Notification dans android avec android studio

Intent intent = new Intent(this, MainActivity.class); 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
      PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, 
        PendingIntent.FLAG_ONE_SHOT); 

      //Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
      Uri defaultSoundUri = Uri.parse("android.resource://"+this.getPackageName()+"/"+R.raw.power); 
      //Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 

      Notification.Builder notificationBuilder = new Notification.Builder(this) 
        .setSmallIcon(R.mipmap.colantaico) 
        .setContentTitle(Titulo) 
        .setContentText(messageBody) 
        .setAutoCancel(true) 
        .setSound(defaultSoundUri) 
        .setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 }) 
        .setLights(Color.RED, 3000, 3000) 
        .setContentIntent(pendingIntent); 

      Notification mNotification = notificationBuilder.build(); 

      mNotification.flags |= Notification.FLAG_INSISTENT; 
      mNotification.sound = defaultSoundUri; 
      NotificationManager notificationManager = 
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
      notificationManager.notify(0 /* ID of notification */, mNotification); 

Dans le Manifest

<uses-permission android:name="android.permission.VIBRATE" /> 
<service 
      android:name=".RecibidorNotificacionesFCM"> 
      <intent-filter> 
       <action android:name="com.google.firebase.MESSAGING_EVENT"/> 
      </intent-filter> 
     </service> 

Répondre

0
private static final int NOTIFICATION_ID = 1; 

Intent openIntent = new Intent(this, MainActivity.class);; 
PendingIntent contentIntent = PendingIntent.getActivity(this, NOTIFICATION_ID, 
       openIntent, PendingIntent.FLAG_ONE_SHOT); 

NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         .setDefaults(Notification.DEFAULT_ALL) 
         .setVibrate(new long[]{100, 250, 100, 250, 100, 250}) 
         .setAutoCancel(true) 
         .setColor(this.getResources().getColor(R.color.activity_toolbar_color)) 
         .setContentTitle("Test Notification") 
         .setStyle(new NotificationCompat.BigTextStyle() 
           .bigText(Html.fromHtml("Notification text"))) 
         .setPriority(Notification.PRIORITY_MAX) 
         .setContentText(Html.fromHtml("Notification text"))) 

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      mBuilder.setSmallIcon(R.drawable.notification_icon1); 
} else { 
      mBuilder.setSmallIcon(R.drawable.notification_icon); 
} 
mBuilder.setContentIntent(contentIntent); 
mBuilder.setDeleteIntent(LocalNotificationEventReceiver.getDeleteIntent(this)); 


NotificationManager notificationManager = 
       (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

Notification notification = mBuilder.build(); 
notificationManager.notify(NOTIFICATION_ID, notification); 
+0

Désolé, non, gardez même, aucun son ou vibrent – Cristian