0

Je souhaite localiser la notification Firebase envoyée par le serveur. Par php, j'envoie une notification à distance à l'appareil Android. Le postdata suivant, je me sers en php:Comment localiser le texte du corps de notification distant Firebase dans Android?

$postData = array(
 
    \t \t \t 'to' => ''.$fcmtoken, 
 
\t \t \t \t 'priority' => 'high', 
 
    \t \t \t 'notification'=> array("body"=> "message body", "loc_key" => "body_key" "title"=> "message title",     "icon" => "ic_stat_gdr_notification_icon", 
 
      "sound" => "default"), 
 
\t \t);

La notification est envoyée sur l'appareil avec le corps du texte 'du corps du message. Mais je veux que le texte localisé ('Cuerpo del menage') de la clé « body_key » devrait être montré

s'il vous plaît également vérifier le code Android que je recevais le message:.

notificationBuilder = new NotificationCompat.Builder(this) 
 
          .setSmallIcon(R.drawable.ic_stat_gdr_notification_icon) 
 
          .setContentTitle(from) 
 
          .setContentText(message) 
 
          .setSound(defaultSoundUri) 
 
          .setContentIntent(contentIntent) 
 
          .setStyle(new NotificationCompat.BigTextStyle().bigText(message)); 
 

 
       } 
 

 
       NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
 
       manager.notify(1, notificationBuilder.build());

Ici, je ne sais pas comment utiliser la clé que j'ai obtenue du message de notification pour la localiser: la loc_key est une chaîne, mais dans Android, elle attend que 'integer' soit passé avec cette méthode: getResources () .getString (R.string.body_key) où 'R.string.body_key' est un entier

Alors, comment puis-je passer la loc_key dans la méthode getString() et obtenir du texte localisé? Aidez-moi, s'il vous plaît.

Répondre

0

Vous pouvez obtenir l'identifiant entier correspondant à votre body_key comme celui-ci

public static int getStringIdentifier(Context context, String name) { 
    return getResources().getIdentifier(name, "string", 
     getPackageName()); 
} 


getResources() 
.getString(getStringIdentifier(getApplicationContext(),loc_key)); 
+0

Merci beaucoup. Ça fonctionne maintenant!!! –