gpt4 book ai didi

android - 构建通知时出错

转载 作者:太空狗 更新时间:2023-10-29 15:12:17 25 4
gpt4 key购买 nike

我正在使用本教程 http://www.vogella.com/articles/AndroidNotifications/article.html , 我要建立通知

//准备在以下情况下触发的 Intent //通知被选中

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

// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
.setContentTitle("New mail from " + "test@gmail.com")
.setContentText("Subject")
.setSmallIcon(R.drawable.icon)
.setContentIntent(pIntent)
.addAction(R.drawable.icon, "Call", pIntent)
.addAction(R.drawable.icon, "More", pIntent)
.addAction(R.drawable.icon, "And more", pIntent).build();


NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);

// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);

我在 addAction 行中有错误,eclipse 说 方法 addaction(ing, String pendingintent) 未定义类型 notification.builder

最佳答案

您需要设置您的 sdkTargetVersion<uses-sdk> AndroidManifest.xml 的元素年满 16 岁或以上。 addAction(...)旧版本的 Android 不存在该方法。

关于android - 构建通知时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15760097/

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