- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我试图在一段时间间隔后显示不同的通知,但发生的事情是它用新的通知更新当前的 PendingIntent
结果我只收到一个通知,即使我触发 4 - 5 pending Intent 请求
点击按钮我做了以下事情
try{
adapter.OpenDB();
int id = adapter.getMaxId("reminder")+1;
adapter.CloseDB();
Intent intent = new Intent(MilestonesActivity.this, AlarmReceiver.class);
intent.putExtra("message", ""+editMsg.getText()+" "+editDate.getText());
intent.putExtra("id", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(MilestonesActivity.this, 0,
intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP,
reminddate.getTimeInMillis(), pendingIntent);
adapter.CloseDB();
}catch (Exception e) {
// TODO: handle exception
}
AlarmReceiver.java
@Override
public void onReceive(Context context, Intent intent) {
Intent i =new Intent(context, NotificationService.class);
try{
int id = intent.getExtras().getInt("id");
i.putExtra("id", id);
CharSequence message = intent.getExtras().getString("message");
i.putExtra("message", message);
}catch (Exception e) {
// TODO: handle exception
}
context.startService(i);
}
通知服务.java
public void show(Intent intent) {
try{
NotificationManager nm;
Log.e("recieve", "ok");
nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "Lawyer app Reminder";
CharSequence message = intent.getExtras().getString("message");
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, new Intent(),
PendingIntent.FLAG_ONE_SHOT);// also tried FLAG_UPDATE_CURRENT
int id =intent.getExtras().getInt("id");
Log.e("I", ""+id);
Notification notif = new Notification(R.drawable.message_active,
"Lawyer app Reminder.", System.currentTimeMillis());
notif.defaults = Notification.DEFAULT_ALL;
notif.flags = Notification.FLAG_AUTO_CANCEL;
notif.setLatestEventInfo(this, from, message, contentIntent);
nm.notify(id, notif);
}catch (Exception e) {
e.printStackTrace();
}
请帮我解决这个问题。提前致谢
最佳答案
我找到了
pendingintent 构造函数的第二个参数不应该相同(硬编码为 0)
我将它更改为 (int) System.currentTimeMillis() 以便它不应该相同 :)
Intent ni =new Intent(NotificationService.this,ModifyDatabaseService.class);
ni.putExtra("id", ""+id);
PendingIntent contentIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), ni,
PendingIntent.FLAG_ONE_SHOT);
关于android - New PendingIntent 更新当前 Intent ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9700617/
我想了解 PendingIntent.FLAG_NO_CREATE 的行为。我想知道它什么时候返回 null 什么时候不返回。这是事件发生的顺序: alarmIntent = new Intent(c
我正在尝试请求网络,因此我构建了 NetworkRequest 并构建了 PendingIntent, ConnectivityManager conn_manager = (Connectivit
我一直在使用警报管理器。一旦我设置了一个 PendingIntent 来触发警报,我想取消它。 How do I achieve this? 帮助将不胜感激。 最佳答案 下面这几行代码肯定可以帮助您删
我正在尝试在 Android 中创建一个 PendingIntent。这是代码 mNotificationIntent = new Intent(getApplicationContent(), My
我有三个 Activity (Home、Search、Destination),我可以用它们来描述我的用户体验流程。 Home Activity 是我的启动器 Activity ,然后是搜索 Acti
我试图从 API 中了解 PendingIntent 的用途。 有时我使用的一些方法需要这样做,但我仍然没有得到正确的想法。 谁能解释一下吗?为什么我不能只使用上下文? 谢谢 莫希克 最佳答案 Pen
我在 Android 中开发闹钟时遇到问题。当我触发包含必须在计划时间启动的 Activity 的 PendingIntent 时,它运行良好。但是,当闹钟响起并且我按贪睡 5 分钟并使用不同的请求代
我得到了一个 IntentService,它在 onHandleIntent(Intent) 中同步执行一些长时间运行的工作。因此,只要服务运行,我就会显示一个通知。现在我想在用户点击通知后停止服务。
我有这个... button = (Button) findViewById(R.id.start_repeating); button.setOnClickListener(new OnClickL
在我的应用程序中,我有一个显示 2 个选项的对话框:Copy 和 Dismiss 当用户单击 Copy 时,我希望在状态栏中收到通知。 public void showDialog(final Str
我有一个会显示通知的服务。通知显示正确,但当我点击通知时没有任何反应。它应该在我的应用程序中打开一个 Activity 。这是我的代码: public class ServiceCheckExpens
我正在我的游戏中创建一个通知。如果玩家有一段时间没有玩游戏,我想显示通知。我正在使用以下带有警报设置的 PendingIntent 来创建通知。有了这个,我就可以创建通知。 问题:如果玩家玩游戏,我需
所以这段代码是在我的服务开始在前台启动后从内部运行的。这也会创建将留在那里的通知。我有很多问题/疑问: 1) 点击通知只会打开应用信息,不会打开我的 PendingIntent。 2) 未设置我的内容
如何创建多个 PendingIntent?我有几个通知,当用户按下最后一个通知时,一切正常,但点击通知没有响应。我的代码是: Intent notificationIntent = new Inten
我正在运行一项服务,该服务会在特定事件的通知栏上发出通知。在该通知中,我设置了一个 PendingIntent 以启动另一个应用程序。出于某种原因,当我根据通知采取行动时,它不会启动其他应用程序。这是
我有一个名为 sendNotification 的方法,可以多次调用。 private PendingIntent createNotificationIntent(Context context,
我有一个导航应用程序。我想获得可能暂时不会到达的位置信息,具体取决于 GPS 锁定所需的时间——或者接收信号不好时的时间。 我计划使用 LocationManager.requestLocationU
我有一个 Android 库,它有一个创建 Notification 的 Service。据我了解,Notification 必须有一个 contentIntent (PendingIntent) 集
当我们将 0 作为标志传递给 PendingIntent 时,如下所示: PendingIntent pi=PendingIntent.getActivity(this, 1, i, 0); does
我在尝试通过 Intent 和未决 Intent 将数据传递给 BroadcastReceiver 时遇到了一些问题,涉及接近警报。更具体地说,我试图传递一个对象,其中包括用户不断变化的位置。我已经尝
我是一名优秀的程序员,十分优秀!