TaskStackBuilder - 向后兼容与否?

Pri*_*lly 1 stack android

我在这里按照示例设置通知.我的应用程序与API 15和其他版本兼容.这是我的代码:

@Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        // send notification

        // API < 16 so have to use compat
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                //.setSmallIcon(context.getResources().getDrawable(icon_id_here))
                .setContentTitle("My notification")
                .setContentText("Hello World!");
        // Creates an explicit intent for an Activity in your app
        Intent resultIntent = new Intent(context, UpcomingTest.class);

        // The stack builder object will contain an artificial back stack for the
        // started Activity.
        // This ensures that navigating backward from the Activity leads out of
        // your application to the Home screen.
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(UpcomingTest.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        // mId allows you to update the notification later on.
        mNotificationManager.notify(123, mBuilder.build());

    }
Run Code Online (Sandbox Code Playgroud)

当读取信息,这里大约TaskStackBuilder,它说:"TaskStackBuilder提供服从于平台的设备的版本各地交任务导航正确约定的向后兼容的方式." 但是我收到一个错误,说我需要以最小API 16为目标才能使用TaskStackBuilder.还有什么我需要做的才能真正使它向后兼容吗?

ian*_*ake 6

您可能正在导入android.app.TaskStackBuilder而不是android.support.v4.app.TaskStackBuilder - 检查您的导入.