Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/386.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-使用NotificationListener服务接收日历提醒通知_Java_Android_Notifications_Calendar - Fatal编程技术网

Java Android-使用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

我在使用NotificationListener服务时遇到两个问题

  • 我在我的应用程序中使用了NotificationListenerService类。此侦听器onNotificationPosted方法接收所有通知
  • 我的代码如下所示

    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
    {
    公告发布时的公共作废(状态通知状态通知)
    {
    //接收所有通知。
    //我只需要收到提醒通知
    }
    //.....
    ......
    }
    //我的理发师喜欢下面
    
    但我只需要收到日历提醒通知

    如何添加筛选器以仅接收日历提醒通知

  • 当我打开通知访问时,它显示以下消息

    允许对MyApp进行通知访问?

    MyAPP将能够读取所有通知,包括个人通知 联系人姓名和您收到的邮件文本等信息 接收它还可以关闭通知或跳跳虎动作 它们包含的按钮

  • 如何在通知访问对话框中更改上述消息

    如何添加筛选器以仅接收日历提醒通知

    • 为了过滤谷歌的日历,我们可以监听通知 使用
      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);
    
    
        }
    
    }