我正在制作通知应用程序并努力解决以下错误:
java.lang.IllegalArgumentException: com.tonyapp.rabbitfarm: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.
at android.app.PendingIntent.checkFlags(PendingIntent.java:375)
at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:645)
at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
at com.allyants.notifyme.NotifyMe.scheduleNotification(NotifyMe.java:159)
at com.allyants.notifyme.NotifyMe.<init>(NotifyMe.java:89)
at com.allyants.notifyme.NotifyMe$Builder.build(NotifyMe.java:327)
at com.tonyapp.rabbitfarm.NotesTakerActivity.onTimeSet(NotesTakerActivity.java:291)
at com.wdullaer.materialdatetimepicker.time.TimePickerDialog.notifyOnDateListener(TimePickerDialog.java:1893)
at com.wdullaer.materialdatetimepicker.time.TimePickerDialog.lambda$onCreateView$3$com-wdullaer-materialdatetimepicker-time-TimePickerDialog(TimePickerDialog.java:761)
at com.wdullaer.materialdatetimepicker.time.TimePickerDialog$$ExternalSyntheticLambda3.onClick(Unknown Source:2)
at android.view.View.performClick(View.java:7441)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:1202)
at android.view.View.performClickInternal(View.java:7418)
at android.view.View.access$3700(View.java:835)
at android.view.View$PerformClick.run(View.java:28676)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7839)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
我搜索了这个问题的解决方案,但没有适合我的解决方案。
下面是我的 Mainactivity.java 代码:
btnCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
NotifyMe.cancel(getApplicationContext(),"test");
}
});
btnNotify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dpd.show(getSupportFragmentManager(),"DatePickerDialog");
}
});
}
@Override
public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
now.set(Calendar.YEAR,year);
now.set(Calendar.MONTH,monthOfYear);
now.set(Calendar.DAY_OF_MONTH,dayOfMonth);
tpd.show(getSupportFragmentManager(),"timepicker");
}
@Override
public void onTimeSet(TimePickerDialog view, int hourOfDay, int minute, int second) {
now.set(Calendar.HOUR_OF_DAY,hourOfDay);
now.set(Calendar.MINUTE,minute);
now.set(Calendar.SECOND,second);
NotifyMe notifyMe = new NotifyMe.Builder(getApplicationContext())
.title(edt1.getText().toString())
.content(edt2.getText().toString())
.color(255,0,0,255)
.led_color(255,255,255,255)
.time(now)
.addAction(new Intent(),"Snooze",false)
.addAction(new Intent(),"Dismiss",true)
.addAction(new Intent(),"Done")
.large_icon(R.mipmap.ic_launcher_round)
.build();
}
请帮我解决这个问题。提前致谢。