我有一种方法可以创建由参数接收的通知消息,其中用户单击 Habre 带有该消息的新窗口。
我在创建第二个通知时遇到的问题,是否打开了第一个通知,是在这个打开的新屏幕中始终显示第一个通知,尽管如果我把消息正确的话,通知的描述。
我留下代码,我希望 podais 帮助,因为我不坏
建筑规范通知
@SuppressWarnings("deprecation")
private void mostrarNotificacion(Context context, String msg)
{
//Obtenemos una referencia al servicio de notificaciones
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notManager =
(NotificationManager) context.getSystemService(ns);
//Configuramos la notificación
int icono = android.R.drawable.stat_sys_warning;
CharSequence textoEstado = "Alerta!";
long hora = System.currentTimeMillis();
Notification notif =
new Notification(icono, textoEstado, hora);
//Configuramos el Intent
Context contexto = context.getApplicationContext();
CharSequence titulo = "Nuevo Mensaje";
CharSequence descripcion = msg; //Here if you display the right message
Intent notIntent = new Intent(contexto,
MensajeActivity.class);
notIntent.putExtra("mensaje", msg);
PendingIntent contIntent = PendingIntent.getActivity(
contexto, 0, notIntent, 0);
notif.setLatestEventInfo(
contexto, titulo, descripcion, contIntent);
//AutoCancel: cuando se pulsa la notificaión ésta desaparece
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notif.defaults |= Notification.DEFAULT_VIBRATE;
//Enviar notificación
notManager.notify(1, notif);
}
新代码屏幕
public class MensajeActivity extends Activity{
private TextView mensaje;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_mensaje);
mensaje = (TextView)findViewById(R.id.lblMensaje);
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
mensaje.setText(extras.getString("mensaje")); //Here always displays the first message received
}else{
mensaje.setText("vacio");
}
}
}
另一个疑问是。当我收到通知时,如何在应用程序的图标上添加数字?例如sms的图标,sms当一个新的地方一个数字表示有多少已经收到sms
谢谢