gpt4 book ai didi

java - Android 通知生成器 NoSuchMethodFound

转载 作者:行者123 更新时间:2023-12-02 05:13:36 25 4
gpt4 key购买 nike

我正在尝试通过引用Notification Builder在Android推送通知中设置多个内容

代码如下:

public void onReceive(Context context, Intent intent) {
CharSequence eventName = intent.getStringExtra("eventName");
CharSequence eventTime = intent.getStringExtra("eventTime");
CharSequence eventAddr = intent.getStringExtra("eventAddr");

mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(context, 1,
new Intent(), 0);
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(contentIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(eventName)
.setContentText(
"Event venue: " + eventAddr + " Event Time: "
+ eventTime)
.setSmallIcon(R.drawable.ic_launcher).setAutoCancel(true)
.setWhen(System.currentTimeMillis());
Notification notification = builder.build();
mNotificationManager.notify(
Integer.parseInt(intent.getExtras().get("NotifyCount")
.toString()), notification);
}

但我收到这些错误消息:

11-26 17:44:44.943: I/dalvikvm(32480): Could not find method android.app.Notification$Builder.build, referenced from method nyp.edu.eneighbourhood.Alarm.onReceive
11-26 17:44:44.943: W/dalvikvm(32480): VFY: unable to resolve virtual method 296: Landroid/app/Notification$Builder;.build ()Landroid/app/Notification;
11-26 17:44:44.943: D/dalvikvm(32480): VFY: replacing opcode 0x6e at 0x0067
11-26 17:44:44.959: D/AndroidRuntime(32480): Shutting down VM
11-26 17:44:44.959: W/dalvikvm(32480): threadid=1: thread exiting with uncaught exception (group=0x40c7e1f8)
11-26 17:44:44.990: E/AndroidRuntime(32480): FATAL EXCEPTION: main
11-26 17:44:44.990: E/AndroidRuntime(32480): java.lang.NoSuchMethodError: android.app.Notification$Builder.build
11-26 17:44:44.990: E/AndroidRuntime(32480): at nyp.edu.eneighbourhood.Alarm.onReceive(Alarm.java:38)
11-26 17:44:44.990: E/AndroidRuntime(32480): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2133)
11-26 17:44:44.990: E/AndroidRuntime(32480): at android.app.ActivityThread.access$1500(ActivityThread.java:127)
11-26 17:44:44.990: E/AndroidRuntime(32480): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1211)
11-26 17:44:44.990: E/AndroidRuntime(32480): at android.os.Handler.dispatchMessage(Handler.java:99)
11-26 17:44:44.990: E/AndroidRuntime(32480): at android.os.Looper.loop(Looper.java:137)
11-26 17:44:44.990: E/AndroidRuntime(32480): at android.app.ActivityThread.main(ActivityThread.java:4512)
11-26 17:44:44.990: E/AndroidRuntime(32480): at java.lang.reflect.Method.invokeNative(Native Method)
11-26 17:44:44.990: E/AndroidRuntime(32480): at java.lang.reflect.Method.invoke(Method.java:511)
11-26 17:44:44.990: E/AndroidRuntime(32480): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
11-26 17:44:44.990: E/AndroidRuntime(32480): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
11-26 17:44:44.990: E/AndroidRuntime(32480): at dalvik.system.NativeStart.main(Native Method)

有任何指南吗?

提前致谢。

编辑

使用这些代码,我的通知只显示几秒钟,无需我点击它就会自动消失。有什么想法吗?

最佳答案

    NotificationCompat.Builder n;
n=new NotificationCompat.Builder(getApplicationContext())
.setContentTitle("Hello")
.setContentText("Notification")
.setContentIntent(pintent)
.setSmallIcon(R.drawable.ic_launcher);


NotificationCompat.InboxStyle large_content=new NotificationCompat.InboxStyle();

large_content.setBigContentTitle("Hello content");

n.setStyle(inBoxStyle);

NotificationManagerCompat notificationManager =
NotificationManagerCompat.from(getApplicationContext());
notificationManager.notify(1001, n.build());

您正在使用的方法现已弃用。它不会被运行。

pintent --> 这是待处理 Intent 的对象

关于java - Android 通知生成器 NoSuchMethodFound,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27145891/

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