不工作 notificactioncompat 与 firebase
not working notificactioncompat with firebase
我不知道,但我的通知没有显示.. 只能看到带有 Log Consola Android Studio 的消息 u.u
public class MyFcmListenerService extends com.google.firebase.messaging.FirebaseMessagingService {
public static final String TAG = MyFcmListenerService.class.getSimpleName();
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG,"HECHO");
Log.d(TAG,remoteMessage.getData().get("message"));
Log.d(TAG, "token_test_"+Test.getTest(1).getToken_test());
if (Test.getTest(1).isEstado_token()) {
Log.d(TAG,"bolean1"+String.valueOf(Test.getTest(1).isEstado_token()));
mostrarMensaje(remoteMessage.getData().get("message"));
}
}
private void mostrarMensaje(String mensaje) {
SharedPreferences preferences = getSharedPreferences(Constantes.PREFERENCIA_PARA_PREGUNTAS, Context.MODE_PRIVATE);
int pre_token_count = preferences.getInt(Constantes.KEY_IDENTIFICADOR, 0);
Intent i = new Intent(this, PrincipalActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("TEST")
.setContentText(mensaje)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVibrate(new long[]{2000, 2000, 2000, 2000, 2000});
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(pre_token_count, builder.build());
SharedPreferences.Editor editor = preferences.edit();
pre_token_count++;
editor.putInt(Constantes.KEY_IDENTIFICADOR, pre_token_count);
editor.commit();
}
}
我的留言是"Bien joven :D"..
enter image description here
小鹿
documentation表示通知需要有图标:
A Notification object must contain the following:
- A small icon, set by
setSmallIcon()
- A title, set by
setContentTitle()
- Detail text, set by
setContentText()
使用 setSmallIcon() 在您的通知中添加一个图标。
我不知道,但我的通知没有显示.. 只能看到带有 Log Consola Android Studio 的消息 u.u
public class MyFcmListenerService extends com.google.firebase.messaging.FirebaseMessagingService {
public static final String TAG = MyFcmListenerService.class.getSimpleName();
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG,"HECHO");
Log.d(TAG,remoteMessage.getData().get("message"));
Log.d(TAG, "token_test_"+Test.getTest(1).getToken_test());
if (Test.getTest(1).isEstado_token()) {
Log.d(TAG,"bolean1"+String.valueOf(Test.getTest(1).isEstado_token()));
mostrarMensaje(remoteMessage.getData().get("message"));
}
}
private void mostrarMensaje(String mensaje) {
SharedPreferences preferences = getSharedPreferences(Constantes.PREFERENCIA_PARA_PREGUNTAS, Context.MODE_PRIVATE);
int pre_token_count = preferences.getInt(Constantes.KEY_IDENTIFICADOR, 0);
Intent i = new Intent(this, PrincipalActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,i,PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setContentTitle("TEST")
.setContentText(mensaje)
.setContentIntent(pendingIntent)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setVibrate(new long[]{2000, 2000, 2000, 2000, 2000});
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
manager.notify(pre_token_count, builder.build());
SharedPreferences.Editor editor = preferences.edit();
pre_token_count++;
editor.putInt(Constantes.KEY_IDENTIFICADOR, pre_token_count);
editor.commit();
}
}
我的留言是"Bien joven :D".. enter image description here
小鹿
documentation表示通知需要有图标:
A Notification object must contain the following:
- A small icon, set by
setSmallIcon()
- A title, set by
setContentTitle()
- Detail text, set by
setContentText()
使用 setSmallIcon() 在您的通知中添加一个图标。