【发布时间】:2015-04-17 13:47:37
【问题描述】:
我知道这可能是一个重复的问题,但其他问题没有回答我的问题。
我正在开发一个应用程序,该应用程序从状态栏中提取通知(特别是新 WhatsApp 消息的通知)并读取其内容。我已经成功提取了通知标题和消息内容。
问题是,当收到多条未读消息时,通知会从使用EXTRA_TEXT
切换到EXTRA_SUMMARY_TEXT
(然后返回例如"2 new messages"
。
必须能够以某种方式分隔消息,就像某些现有应用程序那样(例如,Snowball 将所有消息合并并显示在一个位置,即使已收到多条消息但仍未阅读,也会显示消息内容)。
我知道用户可以通过 Intents 发送消息。但是,我似乎无法访问传入的意图,因此假设 WhatsApp 使用显式意图来发送消息。
Intent i = new Intent("com.test.testapp.NOTIFICATION_LISTENER");
Bundle extras = sbn.getNotification().extras;
if(sbn.getPackageName().contains("com.whatsapp"))
{
String title = extras.getString(Notification.EXTRA_TITLE);
String summary = extras.getString(Notification.EXTRA_SUMMARY_TEXT);
String msg = extras.getString(Notification.EXTRA_TEXT);
if(msg != null)
{
i.putExtra("notification_event", msg);
}
else
{
i.putExtra("notification_event", summary);
}
}
else
{
i.putExtra("notification_event","...");
}
sendBroadcast(i);
我的问题:
如何在不将"2 new messages"
作为内容的情况下显示所有收到的消息,或者有更好的方法吗?
我需要访问消息内容、发件人号码和收到消息的时间,以便将其保存到数据库中。
任何帮助将不胜感激。
【问题讨论】:
标签: android android-intent android-notifications whatsapp