我想从StatusBarNotification
-object 中获取尽可能多的信息。现在,唯一可以访问的“可靠”信息是tickerText
-property。我正在使用以下代码通过 获取通知的标题和文本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、SMS 等)“手动编码”资源 ID,但这可能会在这些应用程序更新时随时中断。谢谢!