Java Android-使用NotificationListener服务接收日历提醒通知
我在使用NotificationListener服务时遇到两个问题Java Android-使用NotificationListener服务接收日历提醒通知,java,android,notifications,calendar,Java,Android,Notifications,Calendar,我在使用NotificationListener服务时遇到两个问题 我在我的应用程序中使用了NotificationListenerService类。此侦听器onNotificationPosted方法接收所有通知 我的代码如下所示 public class MyListener extends NotificationListenerService { public void onNotificationPosted(StatusBarNotification statusBarN
public class MyListener extends NotificationListenerService
{
public void onNotificationPosted(StatusBarNotification statusBarNotification)
{
//Receive all notification.
// I need to receive reminder notification only
}
//.....
......
}
//My Manifiest like below
<service
android:name=".MyListener"
android:enabled="true"
android:label="@string/app_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService"/>
</intent-filter>
</service>
公共类MyListener扩展了NotificationListenerService
{
公告发布时的公共作废(状态通知状态通知)
{
//接收所有通知。
//我只需要收到提醒通知
}
//.....
......
}
//我的理发师喜欢下面
但我只需要收到日历提醒通知
如何添加筛选器以仅接收日历提醒通知
- 为了过滤谷歌的日历,我们可以监听通知
使用
包名发布com.google.android.calendar
- 要筛选提醒通知,我们可以侦听通知
使用
类别发布 . (API 23+)提醒
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
}谢谢@adneal,提醒过滤器-根据您的编码,它将在通知发布后进行检查。在收到通知之前可以这样做吗?不,听起来不可能。非常感谢@adnealThanks@Happy Singh,可以从onReceive方法获取通知标题吗?
startActivity(new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS)
<receiver
android:name=".Calendar.CatchChangesReceiver"
android:exported="true"
android:priority="1000">
<intent-filter>
<!-- <action android:name="android.intent.action.PROVIDER_CHANGED" />-->
<action android:name="android.intent.action.EVENT_REMINDER" />
<data android:scheme="content" />
<data android:host="com.android.calendar" />
</intent-filter>
</receiver>
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equalsIgnoreCase(CalendarContract.ACTION_EVENT_REMINDER)) {
//Do Something Here to get EVENT ID
Uri uri = intent.getData();
String alertTime = uri.getLastPathSegment();
String selection = CalendarContract.CalendarAlerts.ALARM_TIME + "=?";
Cursor curs = context.getContentResolver().query(CalendarContract.CalendarAlerts.CONTENT_URI_BY_INSTANCE, new String[]{CalendarContract.CalendarAlerts.EVENT_ID, CalendarContract.CalendarAlerts.TITLE}, selection, new String[]{alertTime}, null);
}
}