我希望能够从 StatusBarNotification
对象中获取尽可能多的信息。目前,唯一可访问的“可靠”信息是 tickerText
属性。我使用以下代码通过 RemoteViews
获取通知的标题和文本,但很多时候,标题和/或文本将会简单地为 null :-(:
//Get the title and text
String mTitle = "";
String mText = "";
try {
RemoteViews remoteView = sbn.getNotification().contentView;
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup localView = (ViewGroup) inflater.inflate(remoteView.getLayoutId(), null);
remoteView.reapply(getApplicationContext(), localView);
TextView tvTitle = (TextView) localView.findViewById(android.R.id.title);
TextView tvText = (TextView) localView.findViewById(16908358);
mTitle = (String)tvTitle.getText();
mText = (String)tvText.getText();
} catch (Exception e){
Log.e(TAG, "Error getting notification title/text: " + e);
}
有没有其他(更可靠的)方法?我可以手动编码“流行”的通知(如Gmail、短信等)的资源ID,但这可能会在这些应用程序更新时随时中断。谢谢!