旧版Android上的TaskStackBuilder

时间:2013-12-16 23:56:30

标签: android notifications

我需要在Android Notification上显示GingerBread,但我使用的TaskStackBuilder来自Android版本3及更高版本。

NotificationCompat.Builder notification = 
        new NotificationCompat.Builder(context)
            .setSmallIcon(R.drawable.red)
            .setContentTitle("Notification.")
            .setContentText(incomingNumber);

Intent resultIntent = new Intent(context, MainActivity.class);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);
stackBuilder.addNextIntent(resultIntent);

PendingIntent resultPendingIntent =
        stackBuilder.getPendingIntent(
            0,
            PendingIntent.FLAG_UPDATE_CURRENT
        );

notification.setContentIntent(resultPendingIntent);

NotificationManager mNotificationManager =
    (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

mNotificationManager.notify(1, notification.build());

我怎样才能在Android< V3.0?

1 个答案:

答案 0 :(得分:0)

TaskStackBuilder在Android上工作正常< 3.0,您只需使用支持库中的版本。