2

我在 android 中玩通知,我想知道为什么 NotificationCompat 没有像在 Jellybean 中那样显示大图标和 Gingerbread 中的数字(参见图片),我认为它是为此目的而创建的?

这是我触发通知的方式:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Button btnShow = (Button)findViewById(R.id.btnNotif);

    Intent intent = new Intent(this, NotificationReceiverActivity.class);
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0);

    notificationManager =  (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);


        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setWhen(System.currentTimeMillis())
        .setContentText("You are near your point of interest.")
        .setContentTitle("Proximity Alert!")
        .setSmallIcon(android.R.drawable.ic_menu_info_details)
        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.orchide))
        .setAutoCancel(true)
        .setTicker("Proximity Alert!")
        .setNumber(10)
        .setContentIntent(pIntent)
        .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_VIBRATE| Notification.DEFAULT_SOUND);
        /*Create notification with builder*/
         notification=notificationBuilder.build();

        /*sending notification to system.Here we use unique id (when)for making different each notification
         * if we use same id,then first notification replace by the last notification*/
    btnShow.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            notificationManager.notify(1000, notification);
        }

    });



}

姜饼通知

果冻豆中的通知

4

1 回答 1

3

在预蜂窝 API 级别上忽略大图标。

NotificationCompat.Builder 文档说: ......在不提供扩展通知的平台版本上,依赖扩展通知的方法无效......

如果您查看 NotificationCompat.Builder 源代码,您会看到大图标用于蜂窝及以上。

于 2013-02-11T16:21:33.440 回答