1

ユーザーがそのメッセージで新しいウィンドウをHabreをクリックしているパラメーターによって受信された通知メッセージを作成するメソッドがあります。

2 番目の通知を作成するときに発生する問題は、最初の通知を開いたかどうかに関係なく、この新しい画面では常に最初の通知が表示されますが、メッセージを正しく入力すると通知の説明が表示されます。

私はコードを残します。私は悪くないので、ポダイが助けてくれることを願っています

建築基準法の通知

@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

ありがとう

4

0 に答える 0