gpt4 book ai didi

Android通知栏构建方法错误

转载 作者:行者123 更新时间:2023-11-29 02:00:17 25 4
gpt4 key购买 nike

我是 Android 新手,需要一些帮助。我似乎无法掌握如何构建新的 Notification.Builder 实例。遗憾的是,我正在遵循的教程使用了一个较旧的构造函数,在仔细阅读 android 引用文档后,它清楚地说明了这一点。我创建了一个按钮,当您按下它时,它只会提供一个简单的通知。在找到其他示例后所有代码似乎都没有问题,但是在构建方法下的 Eclipse 中出现红线错误。任何帮助将不胜感激:

Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

Context context = Main.this;
Intent intent = new Intent(context, Main.class);
PendingIntent pending = PendingIntent.getActivity(Main.this, 0, intent, 0);

Notification noti = new Notification.Builder(Main.this)
.setTicker("This is important!")
.setContentTitle("PLEASE READ!")
.setContentText("Important message from me!")
.setSmallIcon(android.R.drawable.stat_notify_more)
.setWhen(System.currentTimeMillis())
.setContentIntent(pending)
.build();


NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(0, noti);
}
});

最佳答案

Notification.Builder.build() 是 API 级别 16。您可能没有将目标设置为 v16 和/或下载 v16 android 开发工具包,因此 Eclipse 不知道该方法并因此将其标记为无效。

查看 Notification.Builder 的文档

关于Android通知栏构建方法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13018836/

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