相关疑难解决方法(0)

android挂起意图通知问题

我在我的应用程序中发生了一个警报,它会启动一个通知,然后在按下时启动一个活动.问题是,当我创建多个警报时,从通知启动的活动会获得与第一个相同的额外内容.我认为这个问题要么是我在未决意图中的意图,要么是在未决意图本身.我想我可能需要在其中一个上放一面旗帜,但我不知道哪一个.

Intent showIntent =new Intent(context, notificationreceiver.class);
    showIntent.putExtra("details", alarmname);

PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
        showIntent, 0); 

    notification.setLatestEventInfo(context, "The event is imminent",
            alarmname, contentIntent);
Run Code Online (Sandbox Code Playgroud)

和通知的接收者

Bundle b = getIntent().getExtras();
    String eventname = b.getString("details");
    details.setText(eventname);
Run Code Online (Sandbox Code Playgroud)

每次下次通知发生时,"详细信息"额外都是相同的,而不是具有不同的值.直到我设置意图,我确信正确的值转到"详细信息",因此每次按任何通知时都会获得第一个意图的问题.如何才能启动正确的意图呢?希望我尽可能清楚,谢谢!

notifications android android-intent

72
推荐指数
2
解决办法
4万
查看次数

Android保持缓存我的意图额外,如何声明一个保持新鲜额外的待定意图?

几天前,我一直在努力寻找一种方法来为警报使用自定义意图.虽然我得到了明确的答案,我必须根据一些独特的ID来定制Intents,例如.setAction()还是有一些问题.

我用这种方式定义了PendingIntent:

Intent intent = new Intent(this, viewContactQuick.class);
intent.setAction("newmessage"+objContact.getId());//unique per contact
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK ).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP );
intent.putExtra("id", Long.parseLong(objContact.getId()));
intent.putExtra("results", result.toArray());

PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
Run Code Online (Sandbox Code Playgroud)

然后由通知管理器使用

NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(ns);
// first try to clear any active notification with this contact ID
mNotificationManager.cancel(Integer.parseInt(objContact.getId()));

// then raise a new notification for this contact ID
mNotificationManager.notify(Integer.parseInt(objContact.getId()), notification);
Run Code Online (Sandbox Code Playgroud)

这样工作如下:

  • 应用程序为联系人创建消息
  • 提供了联系ID和有关消息的详细信息的意图
  • 通过消息引发通知
  • 用户对通知的操作,应用程序显示意图传递的消息

问题

对于联系人,这可能会发生多次.并且当生成第二条消息时,通知会很好地提出(消息在那里很好)但是当用户操作它使用旧数据的通知时的意图,所以先前的消息被传递而不是全新的消息.

所以,某种意图是缓存和重用以前的额外内容.如何使每个联系人和每个操作都具有唯一性?

android extras android-intent

62
推荐指数
2
解决办法
2万
查看次数

如何创建不同的pendingintent使filterEquals()返回false?

我正在使用AlarmManager设置重复意图,但它已经造成一些小问题,所以希望任何人都可以提供帮助.

摘要

有2个未决意图.一个运行在1000,另一个运行在每天2000.每个包含来自数据库的行id以用于识别目的.代码看起来像这样:

Intent i = new Intent(mContext, ScheduleReceiver.class);
i.putExtra(RuleDBAdapter.KEY_ROWID, (int)taskId);
PendingIntent pi =PendingIntent.getBroadcast(...);
mAlarmManager.set(AlarmManager.RTC_WAKEUP, when.getTimeInMillis(), pi); 
Run Code Online (Sandbox Code Playgroud)

删除:

问题是我们需要删除其中一个.删除待处理意图的正确方法是设置相同的意图,然后从AlarmManager调用cancel.

Android文档:

public void cancel(PendingIntent operation)
删除具有匹配Intent的所有警报.任何类型的警报,其Intent与此匹配的警报(由filterEquals(Intent)定义)将被取消.

public boolean filterEquals(Intent other)
确定两个意图是否相同以进行意图解析(过滤).也就是说,如果他们的行为,数据,类型,类别和类别是相同的.这不会比较意图中包含的任何额外数据.

所以在上面的例子中,如果我做出相同的意图然后取消,上述两个意图将被取消,因为它们来自同一个类/相同的动作等(除了"额外"数据是rowId但filterEquals不关心额外数据).

这有什么解决方法吗?

android repeat alarmmanager android-pendingintent

20
推荐指数
1
解决办法
7671
查看次数

为什么我的可搜索活动的Intent.getAction()为null?

我已经按照SearchManager文档但仍然无法搜索我的应用程序的某个活动.从我的活动中,出现搜索对话框,我输入查询,点击搜索,我的活动重新打开,然后我在日志中看到:

D/SearchDialog(  584): launching Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
I/SearchDialog(  584): Starting (as ourselves) #Intent;action=android.intent.action.SEARCH;launchFlags=0x10000000;component=com.clinkybot.geodroid2/.views.Waypoints;S.user_query=sdaf;S.query=sdaf;end
I/ActivityManager(  584): Starting activity: Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
D/WAYPOINTS( 1018): NI Intent { cmp=com.clinkybot.geodroid2/.views.Waypoints (has extras) }
D/WAYPOINTS( 1018): NI null
D/WAYPOINTS( 1018): NI false 
Run Code Online (Sandbox Code Playgroud)

在我看来,直到最后三行,一切都很好.的"NI"线getIntent().toString(), getIntent().getAction(),及getIntent().hasExtra(SearchManager.QUERY)分别.

ActivityManager似乎正在以正确的操作启动我的活动.然后当我的活动开始时,它不包含任何动作!?我究竟做错了什么?

我的清单的相关部分是:

<activity android:name=".views.Waypoints" android:label="Waypoints" android:launchMode="singleTop">
   <intent-filter>
    <action android:name="android.intent.action.SEARCH" />
    <category android:name="android.intent.category.DEFAULT" />
   </intent-filter>
   <meta-data android:name="android.app.searchable"
    android:resource="@xml/searchable" />
  </activity>
Run Code Online (Sandbox Code Playgroud)

search android action android-intent

13
推荐指数
1
解决办法
4380
查看次数

RecognizerIntent:如何将捆绑包添加到待处理的意图

我正在实现一个响应RecognizerIntent的活动.除此之外,此活动必须处理两个指定待处理意图附加附加内容及其附加内容:

  • EXTRA_RESULTS_PENDINGINTENT
  • EXTRA_RESULTS_PENDINGINTENT_BUNDLE

解释文档:

  • 如果您使用EXTRA_RESULTS_PENDINGINTENT提供a PendingIntent,则结果将添加到其包中,PendingIntent并将结果发送到其目标.

  • 如果您使用EXTRA_RESULTS_PENDINGINTENT提供转发意图,您还可以使用EXTRA_RESULTS_PENDINGINTENT_BUNDLE为最终意图提供额外的额外内容.搜索结果将添加到此捆绑包中,组合捆绑包将发送到目标.

我一直在寻找可以证明以下内容的示例代码.

PendingIntent从捆绑中提取a的最佳方法是什么?

我应该这样做:

(PendingIntent)
        extras.getParcelable(RecognizerIntent.EXTRA_RESULTS_PENDINGINTENT)
Run Code Online (Sandbox Code Playgroud)

如何在一组现有的附加内容中添加额外内容PendingIntent

如何启动修改PendingIntent

android bundle recognizer-intent android-pendingintent

10
推荐指数
1
解决办法
5039
查看次数

DP5 7.0 - 为待处理的意图添加额外功能会失败吗?

在跟踪器上添加关联问题:https://code.google.com/p/android/issues/detail? id = 216581 & thanks = 216581 & ts = 1468962325

所以我今天在我的Nexus 5X上安装了DP5 Android 7.0版本.我一直在开发一个应用程序,它使用Android的AlarmManager类在特定时间安排本地通知.在此版本发布之前,代码在运行KitKat,Lollipop和Marshmallow的设备上运行良好.

以下是我如何安排警报:

Intent intent = new Intent(context, AlarmManagerUtil.class);
            intent.setAction(AlarmManagerUtil.SET_NOTIFICATION_INTENT);
            intent.putExtra(AlarmManagerUtil.REMINDER_EXTRA, Parcels.wrap(reminders));
            intent.putExtra("time", when.getMillis());
            PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            if (alarmManager != null) {
                if (Build.VERSION.SDK_INT >= 23) {
                  alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
                } else if (Build.VERSION.SDK_INT >= 19) {
                    alarmManager.setExact(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
                } else {
                    alarmManager.set(AlarmManager.RTC_WAKEUP, when.getMillis(), pendingIntent);
                }
Run Code Online (Sandbox Code Playgroud)

我的AlarmManagerUtil @onReceive的"SET_NOTIFICATION_INTENT"如下所示:

public void fireNotification(Context context, Intent intent) {
    List<Reminder> reminderToFire = …
Run Code Online (Sandbox Code Playgroud)

android alarmmanager android-notifications parceler android-7.0-nougat

8
推荐指数
1
解决办法
1133
查看次数