Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.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
无法接收android.intent.action.EVENT\u提醒广播_Android_Calendar_Broadcast - Fatal编程技术网

无法接收android.intent.action.EVENT\u提醒广播

无法接收android.intent.action.EVENT\u提醒广播,android,calendar,broadcast,Android,Calendar,Broadcast,我想写一个当日历提醒发生时触发的应用程序。我意识到没有官方记录的方法可以做到这一点,但我在日志中看到,当我的手机(Droid X)上的日历闹钟响起时,AlertReceiver表示它已收到android.intent.action.EVENT_提醒: 01-03 11:03:00.029 D 1523 AlertReceiver onReceive: a=android.intent.action.EVENT_REMINDER Intent { act=android.intent.action

我想写一个当日历提醒发生时触发的应用程序。我意识到没有官方记录的方法可以做到这一点,但我在日志中看到,当我的手机(Droid X)上的日历闹钟响起时,AlertReceiver表示它已收到android.intent.action.EVENT_提醒:

01-03 11:03:00.029 D 1523 AlertReceiver onReceive: a=android.intent.action.EVENT_REMINDER Intent { act=android.intent.action.EVENT_REMINDER dat=content://com.android.calendar/129407058000 flg=0x4 cmp=com.android.calendar/.AlertReceiver (has extras) }
因此,我设置了一个简单的广播接收器:

package com.eshayne.android;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class CalendarTest extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
       android.util.Log.i("CalendarTest", "CalendarTest.onReceive called!");
    }
}
凭此舱单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eshayne.android"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <receiver android:name="com.eshayne.android.CalendarTest">
            <intent-filter>
                <action android:name="android.intent.action.EVENT_REMINDER" />
            </intent-filter>
        </receiver>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eshayne.android"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-permission android:name="android.permission.READ_CALENDAR" />
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".CalendarTestDisplay"
              android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest> 
使用此修改的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eshayne.android"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <receiver android:name="com.eshayne.android.CalendarTest">
            <intent-filter>
                <action android:name="android.intent.action.EVENT_REMINDER" />
            </intent-filter>
        </receiver>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.eshayne.android"
    android:versionCode="1"
    android:versionName="1.0">
    <uses-permission android:name="android.permission.READ_CALENDAR" />
        <application android:icon="@drawable/icon" android:label="@string/app_name" android:debuggable="true">
        <activity android:name=".CalendarTestDisplay"
              android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:minSdkVersion="8" />
</manifest> 

没有更好的结果

你知道我遗漏了什么吗?或者关于如何捕捉日历报警事件的其他想法

谢谢,
Ethan

好吧,你要做的不是Android SDK的一部分,主要是因为日历不是操作系统的一部分

也就是说,您至少需要将
元素添加到
中,因为
意图有一个
Uri


但是,我有理由肯定这不会起作用,因为
意图
还专门标识了一个组件(
com.android.calendar/.AlertReceiver
)。AFAIK,这在一开始就在
Intent
中,因此
Intent
将只传递给该组件,而忽略所有其他路由规则。可以想象,列出的组件只在
Intent
解析后才出现,但我认为这些日志条目不是这样工作的。

可以将广播意图设置为“android.Intent.action.EVENT\u提醒”通过在intent筛选器中指定DataAuthority和DataScheme以及intent操作来工作。您需要将DataAuthority指定为“com.android.calendar”,将DataScheme指定为“content”。

您需要在intent筛选器中将data scheme设置为“content”

使用清单,在意图过滤器中添加数据元素

        <receiver android:name="com.eshayne.android.CalendarTest">
            <intent-filter>
                <data android:scheme="content"/> <!-- this was missing -->
                <action android:name="android.intent.action.EVENT_REMINDER" />
            </intent-filter>
        </receiver>

广播意图“android.intent.action.EVENT\u提醒”仅在需要为提醒发布警报通知时才会触发

为您的事件设置通知(例如:事件前10分钟),以便广播意图“android.intent.action.EVENT\u提醒”要工作

请您发布一些如何工作的示例代码好吗?当通知被取消或点击时,这也可以用来捕获吗?天哪,这需要一些谷歌搜索来整理!将内容方案添加到过滤器中立即解决了我没有收到提醒的问题。谢谢,但是埋得很深!:)