无法接收android.intent.action.EVENT_REMINDER广播 [英] Unable to receive android.intent.action.EVENT_REMINDER broadcast

查看:1129
本文介绍了无法接收android.intent.action.EVENT_REMINDER广播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写时,日历提醒发生时触发的应用程序。我知道没有正式记录在案,这样做的方式,但我已经看到了日志中,当我的日历闹钟在我的手机(Droid X的)熄灭,AlertReceiver表示,它已经收到了android.intent.action.EVENT_REMINDER:

I would like to write an application that is triggered when a calendar reminder occurs. I realize there is no officially documented way of doing this, but I have seen in the log that when my calendar alarm goes off on my phone (Droid X), AlertReceiver indicates that it has received an android.intent.action.EVENT_REMINDER:

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) }

所以,我成立了一个简单的BroadcastReceiver的:

So, I set up a simple BroadcastReceiver:

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>

不幸的是,当我把这个在我的手机,并成立了一个日历事件提醒 - 当提醒警示,我仍然看到AlertReceiver日志条目,但不是我的

Unfortunately, when I put this on my phone and set up a calendar event with a reminder - when the reminder alerts, I still see the AlertReceiver log entry, but not mine.

我也曾在这里读到那些需要通过code登记,而不是在清单中一些系统的意图。于是,我尝试以下,而不是:

I have also read here about some system intents that require registering via code rather than in the manifest. So, I tried the following instead:

package com.eshayne.android;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;

public class CalendarTestDisplay extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        registerReceiver(new BroadcastReceiver() {
                        @Override
                        public void onReceive(Context context, Intent intent) {
                            android.util.Log.i("CalendarTestDisplay", "received broadcast");
                        }           
                     },
                     new IntentFilter("android.intent.action.EVENT_REMINDER"));
    }
}

这个修改清单:

with this modified 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> 

没有较好的效果。

with no better result.

任何想法我可能会丢失?还是有其他的我怎么可能能够捕捉到日历报警事件的想法?

Any ideas what I may be missing? Or any other ideas of how I might be able to capture calendar alarm occurrences?

谢谢, 阮经天

推荐答案

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

Well, what you're trying to do is not part of the Android SDK, mostly because the calendar is not part of the operating system.

话虽这么说,至少,你需要一个&LT增加;数据&GT; 元素的&LT;意向滤光器&gt; ,因为意图有一个乌里

That being said, at minimum, you will need to add a <data> element to your <intent-filter>, since the Intent has a Uri.

不过,我有理由相信这是行不通的,因为意图还专门标识组件( com.android.calendar / .AlertReceiver )。 AFAIK,这是在意图在一开始,因此,意图将只传递到组件,忽略所有其他路由规则。这是可以想象的列出的组件仅意图的决议后出现了,但我不认为这是那些日志条目是如何工作的。

However, I'm reasonably certain that this will not work, since the Intent also specifically identifies a component (com.android.calendar/.AlertReceiver). AFAIK, that was in the Intent at the outset, and therefore the Intent will only be delivered to that component, ignoring all other routing rules. It's conceivable the listed component only showed up after Intent resolution, but I don't think that's how those log entries work.

这篇关于无法接收android.intent.action.EVENT_REMINDER广播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆