我有一个"欢迎"屏幕,可以下载警报应该关闭的时间,但每次用户登陆屏幕时都会设置一个新的警报
这当然会导致多个警报
有什么方法可以检测出今天是否已经设定了?
感谢您的帮助
安迪
java android alarmmanager android-intent android-pendingintent
我有一个警报管理器,我想看看警报是否已经设置,以及是否显示了一个不同的警报对话框,如果尚未设置它.我找到了一些我被告知应该工作的代码,但它不是.此外,如果已设置警报,警报对话框应提供取消警报的选项,但也不起作用.这是我的代码:
boolean alarmUp = (PendingIntent.getBroadcast(Main.this, 1,
new Intent(Main.this, Alarm_Receiver.class),
PendingIntent.FLAG_NO_CREATE) != null);
if (alarmUp){
//Sets up the custom alert dialog layout gathers the selected time for the notifications to be set
LayoutInflater factory = LayoutInflater.from(this);
final View time_picker = factory.inflate(R.layout.dialog_layout2, null);
AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(this);
alertDialogBuilder2.setView(time_picker);
alertDialogBuilder2.setTitle("Select Your Notification Time:");
alertDialogBuilder2
.setMessage("Please select the time when you want the notifications to appear on your phone each day. Please note: If your phone restarts or runs out of battery you …Run Code Online (Sandbox Code Playgroud) 我创建了一个BroadCastReceiver,它使用警报管理器来安排某些事件.
在BroadcastReceiver中,我使用以下代码进行安排.
Intent localIntent = new Intent("com.test.sample");
PendingIntent pi = PendingIntent.getBroadcast(context, 0,
localIntent, 0);
alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
SystemClock.elapsedRealtime() + (5 * 60 * 1000),
pi);
Run Code Online (Sandbox Code Playgroud)
这里的上下文来自接收器的onReceive方法.
我希望在接收其他广播时取消此警报.我知道警报可以取消 alarmManager.cancel(pi);
但是,如果警报管理员是从任何其他活动设置的,那么如何取消PendingIntent来取消它呢?
谢谢
我有一个奇怪的错误。
我收到了一个带有 3 个按钮(后退、下一步、播放/暂停)的通知。我想在启动服务的这三个按钮中的每一个上设置不同的 pendingIntent。这是我的代码:
Intent playPauseIntent = new Intent(MyApp.mainActivity, NotificationService.class);
playPauseIntent.putExtra("do_action", "play");
contentView.setOnClickPendingIntent(R.id.notifPlayPauseImageView, PendingIntent.getService(MyApp.mainActivity, 0, playPauseIntent, PendingIntent.FLAG_UPDATE_CURRENT));
Intent nextRadioIntent = new Intent(MyApp.mainActivity, NotificationService.class);
nextRadioIntent.putExtra("do_action", "next");
contentView.setOnClickPendingIntent(R.id.notifNextImageView, PendingIntent.getService(MyApp.mainActivity, 0, nextRadioIntent, PendingIntent.FLAG_UPDATE_CURRENT));
Intent previousRadioIntent = new Intent(MyApp.mainActivity, NotificationService.class);
previousRadioIntent.putExtra("do_action", "previous");
contentView.setOnClickPendingIntent(R.id.notifPreviousImageView, PendingIntent.getService(MyApp.mainActivity, 0, previousRadioIntent, PendingIntent.FLAG_UPDATE_CURRENT));
notification.contentView = contentView;
mNotificationManager.notify(1, notification);
Run Code Online (Sandbox Code Playgroud)
然后,在我的服务中,我将“do_action”的意图和值定义为额外的:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if(intent != null && intent.getExtras() != null)
{
String action = (String) intent.getExtras().get("do_action"); // BUG HERE ! I always get …Run Code Online (Sandbox Code Playgroud) java android android-intent android-notifications android-pendingintent
我想发送短信(文本或数据),接收方将根据我发送给他的具体网址打开网页浏览器.
我需要澄清一点,我不希望接收方在他身边有某种应用程序,它会收听传入短信的广播.我的意图是网页浏览器的Intent将根据我发送的网址打开,没有应用程序监听它,并且没有用户按下url快捷方式,他在文本消息中获取.
我的想法是,一旦收到(或打开)短信息消息,浏览器的意图就会自动打开.
如果这是可能的话,我会在每个答案中给出正确的方向.
谢谢你们.