消息通知问题

时间:2012-08-06 10:23:27

标签: android android-intent

我有一个方法可以创建一个参数接收的通知消息,用户正在点击该消息,然后点击一个包含该消息的新窗口。

我在创建第二个通知时已经打开第一个通知的问题是,在这个打开的新屏幕中,始终会显示第一个通知,但是如果我将消息正确放在通知的描述中。 / p>

我留下代码,我希望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");
        }       
    }
}

另一个疑问是。当我收到通知时,如何在应用程序的图标上添加数字?例如短信的图标,短信时新的地方是一个数字,表示有多少人收到了短信

感谢

0 个答案:

没有答案