Как отправить 2 строки с помощью уведомления? - PullRequest
0 голосов
/ 18 мая 2011

Я пытаюсь отправить 2 строки с помощью Уведомления, но я не знаю, как мне это сделать. Я использовал putExtra для своих строк, но на другой активности я получаю нулевое значение. Я не знаю, что делать с другой деятельностью. Я читал об этом в сети, но я не понял. Кто-нибудь может мне помочь?

Вот мой код:

private void setNotifiy(){
    notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    CharSequence NotificationTicket = "You have a notification";

    //CharSequence NotificationContent = ;
    CharSequence contentTitle =  "You are close to "+name_shop+"!!!";
    CharSequence contentText ="So,you can go for shopping:)";

    long when = System.currentTimeMillis();

    Notification notification = new Notification(R.drawable.icon,
            NotificationTicket, when);

    Context context = getApplicationContext();

    Intent notificationIntent = new Intent(this, ShopsOnMap.class);
    notificationIntent.putExtra("latshop",lat_choose);

    notificationIntent.putExtra("longshop", long_choose);

    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);


    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    notificationManager.notify(NOTIFICATION_ID, notification);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
            | Intent.FLAG_ACTIVITY_SINGLE_TOP);

}

В классе ShopsOnMap я написал так:

String q = getIntent().getStringExtra("latshop");
System.out.println("!!"+q+"$$");

и я получаю q = null.

Мне нужен простой пример или любая идея, которая могла бы мне помочь. Спасибо.

1 Ответ

0 голосов
/ 18 мая 2011

Используйте FLAG_UPDATE_CURRENT в вашем вызове getActivity() вместо 0 для четвертого параметра, чтобы ваши новые Intent дополнительные функции применялись к PendingIntent.

...