获取推送通知(android)的内容?

时间:2015-01-27 21:52:28

标签: android notifications push-notification

经过2天的奋斗,我不得不寻求帮助。

目标:将旧邮件与新邮件连接起来。

问题:如何从通知中提取文字?

注意:通知由同一个捆绑包和相同的ID更新。

此代码在收到消息时创建通知:

    private void showNotification(String username, String msg) 
{    
    String title = getString(R.string.msg_notification_title) ;     
    String text =username + ": " +msg;
    if (firstTime) {

        mBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.notification)
        .setAutoCancel(true)
        .setContentTitle(title); 
        firstTime = false;
    }
    else {
            // messages concatination should take place here
    }

    mBuilder.setContentText(text);

    mBuilder.setVibrate(new long[] { 1000, 1000, 1000, 1000, 1000 });

    mBuilder.setLights(Color.CYAN, 3000, 3000);

    mBuilder.setSound(Uri.parse("android.resource://" + getPackageName() + "/" +R.raw.notification_ring));


    Intent i = new Intent(this, Messaging.class);
    i.putExtra(FriendInfo.USERNAME, username);
    i.putExtra(MessageInfo.MESSAGETEXT, msg);   
    i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP); 


    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    stackBuilder.addParentStack(Messaging.class);

    stackBuilder.addNextIntent(i);

    PendingIntent contentIntent =stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);

    mBuilder.setContentIntent(contentIntent); 

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

    String[] events = new String[6];

    inboxStyle.setBigContentTitle("Event tracker details:");

    for (int s=0; s < events.length; s++) {

        inboxStyle.addLine(events[s]);
    }

    mBuilder.setStyle(inboxStyle);

    mNM.notify(1, mBuilder.build());
}

提前感谢。

0 个答案:

没有答案