使用通知类的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);
        }
根据我的日志,显示通知时不会引发异常。但是,位图不会显示在通知中,仅显示在应用程序图标上。 有任何想法吗?     
已邀请:
        听起来您的代码不起作用,并且正在使用非蜂窝通知。尝试使用以下方法检测Honeycomb或更高版本:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    ...
}
    
        您是否尝试过Notification.BigPictureStyle?它应该做的工作。 http://developer.android.com/reference/android/app/Notification.BigPictureStyle.html     

要回复问题请先登录注册