使用通知类的largeIcon字段,例如Gmail通知
||
我正在开发一个显示传入消息通知的应用程序。我希望通知显示位图而不是应用程序图标。
我相信我只能使用Notification类中的largeIcon字段在Honeycomb中做到这一点。
我正在使用反射来确定设备是否正在运行Honeycomb,如果是,我将使用位图填充largeIcon字段,如下所示:
Notification notification = new Notification(icon, ticketText, when);
String sClassName = \"android.app.Notification\";
try {
@SuppressWarnings(\"rawtypes\")
Class classToInvestigate = Class.forName(sClassName);
String strNewFieldName = \"largeIcon\";
Field largeIconField = classToInvestigate.getField(strNewFieldName);
largeIconField.set(notification, photoBitmap);
Log.e(TAG, \"Notification bitmap worked properly\");
} catch (ClassNotFoundException e) {
Log.e(TAG, \"Notification bitmap error; ClassNotFoundException: \" + e);
} catch (NoSuchFieldException e) {
Log.e(TAG, \"Notification bitmap error; NoSuchFieldException: \" + e);
} catch (SecurityException e) {
Log.e(TAG, \"Notification bitmap error; SecurityException: \" + e);
} catch (Exception e) {
Log.e(TAG, \"Notification bitmap error; UnknownException: \" + e);
}
根据我的日志,显示通知时不会引发异常。但是,位图不会显示在通知中,仅显示在应用程序图标上。
有任何想法吗?
没有找到相关结果
已邀请:
2 个回复
臀博
棠媳鳖