gpt4 book ai didi

java - 警报管理器不工作 Android Java

转载 作者:行者123 更新时间:2023-11-30 01:21:08 24 4
gpt4 key购买 nike

我正在 Android Studio 中使用 Java 开发简单的提醒。我使用警报管理器和广播接收器安排警报。当我运行我的程序并安排警报时,不会出现任何警报。但它不会显示任何错误。

主 Activity .java

final Intent intentAlarm = new Intent(this, Doritos.class);
EditText cas = (EditText) findViewById(R.id.editText);
EditText datum = (EditText) findViewById(R.id.editText2);
EditText text = (EditText) findViewById(R.id.editText5);
String Datum[] = datum.getText().toString().split(":");
String Cas[] = cas.getText().toString().split(":");
Calendar cal = new GregorianCalendar(Integer.parseInt(Datum[2]),Integer.parseInt(Datum[1]) - 1,Integer.parseInt(Datum[0]),Integer.parseInt(Cas[0]),Integer.parseInt(Cas[1]),Integer.parseInt(Cas[2]));
final AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
intentAlarm.putExtra("text", text.getText());
alarmManager.set(alarmManager.RTC_WAKEUP, cal.getTimeInMillis(), PendingIntent.getBroadcast(this, pocet, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT));

广播接收器.java (Doritos.java)

public class Doritos extends BroadcastReceiver{

private MainActivity sss = new MainActivity();
@Override
public void onReceive(Context context, Intent intent) {
ToneGenerator toneG = new ToneGenerator(AudioManager.STREAM_ALARM, 100);
toneG.startTone(ToneGenerator.TONE_CDMA_ALERT_CALL_GUARD, 200);

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
mBuilder.setSmallIcon(R.drawable.ic_error_outline_black_24dp);
mBuilder.setContentTitle("Nezabudnicek");
mBuilder.setContentText(intent.getExtras().getCharSequence("text"));
Intent resultIntent = new Intent(context,MainActivity.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(MainActivity.class);

stackBuilder.addNextIntent(resultIntent);
PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(sss.pocet,PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(sss.pocet, mBuilder.build());
}

最佳答案

查看 list 。您可能忘记在那里添加广播接收器。希望对你有帮助

关于java - 警报管理器不工作 Android Java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37086364/

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