0
Upon receiving the notification the text is not displayed completely, at the end of the text an ellipsis is shown, how to resolve this.
Below the notification sending code
enviaNotificacaoDenuncia("Sua Denúncia foi protocolada numero: "+getProcesso().getNumProcesso(), getProcesso().getDenuncia().getToken());
Below is the method used to process the shipment.
public void enviaNotificacaoDenuncia(String mensagem, String token) {
Sender sender = new Sender(apiKey);
Message message = new Message.Builder()
.addData("message", mensagem)
//.addData("denuncia", getGson().toJson(denuncia, DetalheDenuncia.class))
.build();
try {
Result result = sender.send(message, token, 3);
System.out.println(result.getCanonicalRegistrationId());
System.out.println(result.getErrorCodeName());
System.out.println(result.getMessageId());
//System.out.println(denuncia.getTokenGCM().substring(0, 10));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Erro ao enviar notificação!\n"+e, "Erro", JOptionPane.ERROR_MESSAGE);
atualizaTabela();
desabilitaBotoes();
desabilitaCampos();
limpaCampos();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
JOptionPane.showMessageDialog(this, "Erro ao enviar notificação!\n"+e, "Erro", JOptionPane.ERROR_MESSAGE);
}
//JOptionPane.showMessageDialog(this, "Notificação enviada com Sucesso!", "Informação", JOptionPane.INFORMATION_MESSAGE);
}
Classes used in the App
Fcmlistenerservice
package com.t2ti.cardapiobalcao;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import java.util.Map;
public class DenunciaFcmListenerService extends FirebaseMessagingService {
private static final String TAG = "CardapioFcmLS";
// [START receive_message]
@Override
public void onMessageReceived(RemoteMessage message) {
if (message != null) {
Map<String, String> data = message.getData();
String notificationBody = data.get("message");
Log.d(TAG, "Message: " + notificationBody);
sendNotification(notificationBody);
}
}
// [END receive_message]
/**
* Create and show a simple notification containing the received GCM message.
*
* @param message GCM message received.
*/
private void sendNotification(String message) {
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);
int color = getColor(R.color.blue_dark);//modificar cor da notificação
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_stat_ic_notification)
.setContentTitle("Secretaria do Meio Ambiente")
.setColor(color)
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
}
InstanceIDListenerService
package com.t2ti.cardapiobalcao;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class DenunciaInstanceIDListenerService extends FirebaseInstanceIdService {
private static final String TAG = "DenunciaInstanceIDLS";
private static String token;
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is also called
* when the InstanceID token is initially generated, so this is where
* you retrieve the token.
*/
// [START refresh_token]
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
//TODO: Implement this method to send any registration to your app's servers.
//intentService.sendRegistrationToServer(refreshedToken);
sendRegistrationToServer(refreshedToken);
}
public void sendRegistrationToServer(String token) {
/*
try {
File arquivoXml = new File(getFilesDir(), "pedido.xml");
Serializer serializer = new Persister();
DetalheDenuncia denuncia = new DetalheDenuncia();
if (arquivoXml.exists()) {
denuncia = serializer.read(DetalheDenuncia.class, arquivoXml);
}
denuncia.setTokenGCM(token);
serializer.write(denuncia, arquivoXml);
} catch (Exception e) {
e.printStackTrace();
}
*/
setToken(token);
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
// [END refresh_token]
}
Registrationintentservice
package com.t2ti.cardapiobalcao;
import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.messaging.FirebaseMessaging;
import com.t2ti.cardapio.Constantes;
import java.io.IOException;
public class RegistrationIntentService extends IntentService {
private static final String TAG = "RegIntentService";
private static final String[] TOPICS = {"global"};
private static String token;
public RegistrationIntentService() {
super(TAG);
}
@Override
protected void onHandleIntent(Intent intent) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
try {
// [START register_for_gcm]
// Initially this call goes out to the network to retrieve the token, subsequent calls
// are local.
// [START get_token]
String token = FirebaseInstanceId.getInstance().getToken();
// TODO: Implement this method to send any registration to your app's servers.
sendRegistrationToServer(token);
// Subscribe to topic channels
subscribeTopics(token);
// You should store a boolean that indicates whether the generated token has been
// sent to your server. If the boolean is false, send the token to your server,
// otherwise your server should have already received the token.
sharedPreferences.edit().putBoolean(Constantes.SENT_TOKEN_TO_SERVER, true).apply();
// [END register_for_gcm]
} catch (Exception e) {
Log.d(TAG, "Failed to complete token refresh", e);
// If an exception happens while fetching the new token or updating our registration data
// on a third-party server, this ensures that we'll attempt the update at a later time.
sharedPreferences.edit().putBoolean(Constantes.SENT_TOKEN_TO_SERVER, false).apply();
}
// Notify UI that registration has completed, so the progress indicator can be hidden.
Intent registrationComplete = new Intent(Constantes.REGISTRATION_COMPLETE);
LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}
/**
* Persist registration to third-party servers.
*
* Modify this method to associate the user's GCM registration token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
public void sendRegistrationToServer(String token) {
/*
try {
File arquivoXml = new File(getFilesDir(), "denuncia.xml");
Serializer serializer = new Persister();
DetalheDenuncia denuncia = new DetalheDenuncia();
if (arquivoXml.exists()) {
denuncia = serializer.read(DetalheDenuncia.class, arquivoXml);
}
denuncia.setTokenGCM(token);
//serializer.write(denuncia, arquivoXml);
} catch (Exception e) {
e.printStackTrace();
}
/*
*/
setToken(token);
//return token;
}
/**
* Subscribe to any GCM topics of interest, as defined by the TOPICS constant.
*
* @param token GCM token
* @throws IOException if unable to reach the GCM PubSub service
*/
// [START subscribe_topics]
private void subscribeTopics(String token) throws IOException {
FirebaseMessaging.getInstance().subscribeToTopic("mytopic");
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
// [END subscribe_topics]
}
Instanceidlistenerservice
package com.t2ti.cardapiobalcao;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class DenunciaInstanceIDListenerService extends FirebaseInstanceIdService {
private static final String TAG = "DenunciaInstanceIDLS";
private static String token;
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is also called
* when the InstanceID token is initially generated, so this is where
* you retrieve the token.
*/
// [START refresh_token]
@Override
public void onTokenRefresh() {
// Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
//TODO: Implement this method to send any registration to your app's servers.
//intentService.sendRegistrationToServer(refreshedToken);
sendRegistrationToServer(refreshedToken);
}
public void sendRegistrationToServer(String token) {
/*
try {
File arquivoXml = new File(getFilesDir(), "pedido.xml");
Serializer serializer = new Persister();
DetalheDenuncia denuncia = new DetalheDenuncia();
if (arquivoXml.exists()) {
denuncia = serializer.read(DetalheDenuncia.class, arquivoXml);
}
denuncia.setTokenGCM(token);
serializer.write(denuncia, arquivoXml);
} catch (Exception e) {
e.printStackTrace();
}
*/
setToken(token);
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
// [END refresh_token]
}
It’s not about the mode you send, it’s about the mode you create the
Notification
to display. Please post the code where you do thebuild
of notification– LMaker
edited and posted the app side classes.
– jallisson jallis oliveira band