gpt4 book ai didi

android - TaskStackBuilder - 是否向后兼容?

转载 作者:行者123 更新时间:2023-11-29 14:49:28 25 4
gpt4 key购买 nike

我正在按照示例 here 设置通知.我的应用程序与 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());

}

阅读资料时here关于 TaskStackBuilder,它说“TaskStackBuilder 提供了一种向后兼容的方式来遵守设备平台版本上关于跨任务导航的正确约定。”。但是,我收到一条错误消息,指出我需要以最低 API 16 为目标才能使用 TaskStackBuilder。我还需要做些什么才能使其真正向后兼容吗?

最佳答案

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

关于android - TaskStackBuilder - 是否向后兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23415013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com