Android Notification.extras适用于kitkat以下版本的备选方案

Android Notification.extras适用于kitkat以下版本的备选方案,android,android-notifications,Android,Android Notifications,此代码在4.4及以上版本上运行良好。 对于您需要使用的4.4以下版本的notification.extra的备选方案:notification.setLatestEventInfothis、getextr.string.new\u friend\u request\u exist、, 你有新朋友的要求, 内容意图 NotificationCompat.Builder b = new NotificationCompat.Builder(this)

此代码在4.4及以上版本上运行良好。
对于您需要使用的4.4以下版本的notification.extra的备选方案:notification.setLatestEventInfothis、getextr.string.new\u friend\u request\u exist、, 你有新朋友的要求, 内容意图

          NotificationCompat.Builder b = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_stat_notify_small) // Set the small icon to use in the notification layouts.
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_stat_notify_medium_ridlr))
                .setContentTitle(notif.size() + " new notifications") //Set the title (first row) of the notification, in a standard notification.
                .setContentText("Touch to view");

        b.setContentIntent(contentIntent);

        NotificationCompat.InboxStyle inboxStyle =  new NotificationCompat.InboxStyle();
        try {
            for (Notification n : notif) {
                String title = "<b>"+n.extras.getString("android.title")+"</b>" +" "+ n.extras.getString("android.text");
                inboxStyle.addLine(Html.fromHtml(title));
            }
        } catch (Exception e) {
            Crittercism.leaveBreadcrumb(TAG + " Crash due to some internal error from GCM.");
            e.printStackTrace();
        }

        b.setStyle(inboxStyle);
        Notification n1 = b.build();
        n1.flags |= Notification.FLAG_AUTO_CANCEL;
        n1.defaults |= Notification.DEFAULT_SOUND;
        n1.defaults |= Notification.DEFAULT_VIBRATE;
        mNotificationManager.cancel(notificationNumber - 1); // removing previous notification
        mNotificationManager.notify(notificationNumber, n1);

        notificationReceivedListener();