gpt4 book ai didi

android - Notification Builder 不能接受 "this"作为 "context"的替代,为什么?

转载 作者:行者123 更新时间:2023-11-29 17:56:26 27 4
gpt4 key购买 nike

如何解决这个问题?如果我用 this 替换它。它在构建器上创建了更多错误。我该如何解决?

java类中的所有代码。在这种情况下,功能围绕着 onStartCommand

 public class MyNotificationService extends Service {

@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}

@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
Toast.makeText(this, "OnCreate()", Toast.LENGTH_SHORT).show();
}

@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
Toast.makeText(this, "OnDestroy()", Toast.LENGTH_SHORT).show();
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
Toast.makeText(this, "OnStartCommand()", Toast.LENGTH_SHORT).show();
NotificationManager notificationmanager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationintent = new Intent(this, Reminder_2.class);
PendingIntent pendingintent = PendingIntent.getActivity(this, 0, notificationintent, 0);
int icon=R.drawable.ic_launcher;
long when=System.currentTimeMillis();
Notification.Builder builder = new Builder(this);
builder.setContentIntent(pendingintent);
builder.setAutoCancel(true);
builder.setSmallIcon(icon);
builder.setWhen(when);
builder.setTicker("Notification");
builder.setContentTitle("Title");
builder.setContentText("Content");
Notification notification = builder.build();
notificationmanager.notify(033, notification);
return super.onStartCommand(intent, flags, startId);
}


}

最佳答案

// try this
Notification.Builder builder = new Notification.Builder(this);

关于android - Notification Builder 不能接受 "this"作为 "context"的替代,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19018655/

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