Tag: android pendingintent

多个通知给同一个活动

我有一个正在从通知栏打开的活动,但是当我做NotificationManager.notify(…) ,我给意向一个不同的包,以便每个通知打开相同的活动,但从DB其他信息彼此。 但是,当我尝试input任何通知(例如有3个通知)时,他们都将我发送给与最后一个通知相同的活动。 尝试了一些标志之后,我真的不知道问题出在哪里(有些标志会使通知进入第一个包的活动)。 我遵循他们在教程中使用它的方式。

从parcelable,contentView或contentIntent提取通知文本

所以我得到了我的AccessibilityService使用下面的代码: @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED) { List<CharSequence> notificationList = event.getText(); for (int i = 0; i < notificationList.size(); i++) { Toast.makeText(this.getApplicationContext(), notificationList.get(i), 1).show(); } } } 阅读创build通知时显示的文本(1)可以正常工作 。 唯一的问题是,我还需要用户打开通知栏时显示的(3)的值。 (2)对我来说并不重要,但是知道如何读出它是很好的。 正如你可能知道的,所有的值都可以不同。 那么,我怎样才能读出(3) ? 我怀疑这是不可能的,但我的notificationList似乎只有一个条目(至less只有一个吐司显示)。 非常感谢! /编辑:我可以提取通知包裹 if (!(parcel instanceof Notification)) { return; } final Notification notification = (Notification) parcel; […]

PendingIntent上使用了什么“requestCode”?

背景: 我正在使用PendingIntent通过AlarmManager进行报警。 问题: 起初我以为要取消以前的那个,我必须提供我以前用过的确切的requestCode来启动报警。 但后来我发现我错了,因为取消API说: 使用匹配的意图删除任何警报。 任何types的意图匹配此警报(由filterEquals(Intent)定义)的警报将被取消。 看“ filterEquals ”,文档说: 确定两个意图是否相同意图解决(过滤)的目的。 也就是说,如果他们的行为,数据,types,类别和类别是相同的。 这并不比较意图中包含的任何额外数据。 所以我没有得到什么“requestCode”是… 问题是: 什么是“requestCode”用于? 如果我使用相同的“requestCode”创build多个警报怎么办? 他们互相覆盖吗?

在AlarmManager中获取活动的PendingIntents列表

我有一种方法来查看debugging目的设备中的活动PendingIntent列表? 我开始使用AlarmManager ,我想看看我的PendingIntent是否正确创build和删除。 看到还有其他PendingIntent在那里,也是一件好事,看看有些应用程序是否在做一些额外的工作。

意图 – 如果活动正在运行,把它放在前面,否则启动一个新的(从通知)

我的应用程序有通知,显然,没有任何标志,每次都会开始一个新的活动,所以我得到了多个相同的活动在彼此之上运行,这是错误的。 我希望它做的是将通知中指定的活动挂起来的意图,如果它已经在运行,否则启动它。 到目前为止,我有这个通知的意图/待决意图是 private static PendingIntent prepareIntent(Context context) { Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } 奇怪的是,它有时是有效的,有时候不会…我觉得我已经尝试了每一个标志的组合。

通知通过旧的意图附加

我正在通过这个代码在BroadcastReceiver中创build一个通知: String ns = Context.NOTIFICATION_SERVICE; NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns); int icon = R.drawable.ic_stat_notification; CharSequence tickerText = "New Notification"; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); notification.defaults |= Notification.DEFAULT_VIBRATE; long[] vibrate = {0,100,200,200,200,200}; notification.vibrate = vibrate; notification.flags |= Notification.FLAG_AUTO_CANCEL; CharSequence contentTitle = "Title"; CharSequence contentText = "Text"; Intent notificationIntent = new […]

PendingIntent不发送意图额外

我的MainActicity启动了一个带有一个名为isNextWeek的boolean额外的Intent RefreshService 。 我的RefreshService进行Notification ,当用户点击它时启动我的MainActivity 。 这看起来像这样: Log.d("Refresh", "RefreshService got: isNextWeek: " + String.valueOf(isNextWeek)); Intent notificationIntent = new Intent(this, MainActivity.class); notificationIntent.putExtra(MainActivity.IS_NEXT_WEEK, isNextWeek); Log.d("Refresh", "RefreshService put in Intent: isNextWeek: " + String.valueOf(notificationIntent.getBooleanExtra(MainActivity.IS_NEXT_WEEK,false))); pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); builder = new NotificationCompat.Builder(this).setContentTitle("Title").setContentText("ContentText").setSmallIcon(R.drawable.ic_notification).setContentIntent(pendingIntent); notification = builder.build(); // Hide the notification after its selected notification.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(NOTIFICATION_REFRESH, […]

从Activity外部调用startActivity()?

我正在使用AlarmManager来触发广播信号的意图。 以下是我的代码: AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent i = new Intent(this, Wakeup.class); try { PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 0); Long elapsed += // sleep time; mgr.set(AlarmManager.RTC_WAKEUP, elapsed, pi); } catch(Exception r) { Log.v(TAG, "RunTimeException: " + r); } 我从一个Activity调用这个代码,所以我不知道我怎么会得到以下错误… ERROR/AndroidRuntime(7557): java.lang.RuntimeException: Unable to start receiver com.wcc.Wakeup: android.util.AndroidRuntimeException: Calling startActivity() from outside of […]

我怎样才能正确传递独特的额外事项,以待处理的意图?

我遇到了一个与alarmManager和挂起的意图与extras将与之一起的问题。 如果我设置了多个闹钟,他们将会closures,但附加function保持不变。 我已经读过这些问题: android等待意图通知问题 Android继续caching我的意图额外,如何申报一个待定的意图,保持新鲜的额外? 我曾试过: 为每个未决意图分配一个唯一的ID和 使用所有悬而未决的意图标志, 一切都无济于事。 我不知道为什么它不起作用。 这是一个代码片段: Intent intent = new Intent(con, AppointmentNotificationReciever.class); intent.putExtra("foo", bar.toString()); int id = randomNum; PendingIntent sender = PendingIntent.getBroadcast(con, id, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager am = (AlarmManager) con.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, scheduleExecution, sender);

PendingIntent为第一个通知正确地工作,但其余的不正确

protected void displayNotification(String response) { Intent intent = new Intent(context, testActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, Intent.FLAG_ACTIVITY_NEW_TASK); Notification notification = new Notification(R.drawable.icon, "Upload Started", System.currentTimeMillis()); notification.setLatestEventInfo(context, "Upload", response, pendingIntent); nManager.notify((int)System.currentTimeMillis(), notification); } 这个函数将被多次调用。 我想每个notification单击时启动testActivity。 不幸的是,只有第一个通知启动了testActivity。 点击其余的会导致通知窗口最小化。 额外的信息:函数displayNotification()在一个名为UploadManager的类中。 Context从实例化的activity传递到UploadManager 。 函数displayNotification()在同一个AsyncTask运行的UploadManager中的函数被多次调用。 编辑1:我忘了提及,我作为一个extra传递string响应到Intent intent 。 protected void displayNotification(String response) { Intent intent = new Intent(context, testActivity.class); […]