Android 使用通知类的largeIcon字段,如Gmail通知

Android 使用通知类的largeIcon字段,如Gmail通知,android,reflection,notifications,android-3.0-honeycomb,Android,Reflection,Notifications,Android 3.0 Honeycomb,我正在开发一个应用程序,用于显示传入消息的通知。我希望通知显示位图,而不是应用程序图标。 我相信我只能在Honeycom中使用Notification类中的largeIcon字段来实现这一点。 我正在使用反射来确定设备是否正在运行Honeycom,如果是,我将用位图填充largeIcon字段,如下所示: Notification notification = new Notification(icon, ticketText, when); String sClassName = "andro

我正在开发一个应用程序,用于显示传入消息的通知。我希望通知显示位图,而不是应用程序图标。 我相信我只能在Honeycom中使用Notification类中的largeIcon字段来实现这一点。 我正在使用反射来确定设备是否正在运行Honeycom,如果是,我将用位图填充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);
        }
根据我的日志,在显示通知时不会触发异常。但是,位图不会显示在通知上,只显示应用程序图标


有什么想法吗?

听起来好像你的代码不工作了,而且正在使用非蜂窝状通知。尝试此操作以检测蜂窝状或更高版本:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
    ...
}

你试过Notification.BigPictureStyle吗?它应该能完成任务。

我应该提供更多的上下文吗?这是使用反射的正确方法吗?