无法接收android.intent.action.EVENT_REMINDER广播

问题描述 投票:7回答:5

我想,当写在日历提醒发生时所触发的应用。我知道没有正式记录在案这样的方式,但我在日志中看到,当我的日历警报响起时我的手机(Droid X的)上,AlertReceiver表明它已收到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) }

所以,我成立了一个简单的广播接收器:

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日志条目,但不是我的。

我也曾在这里阅读有关需要通过代码注册,而不是在清单一些系统的意图。所以,我想,而不是执行以下操作:

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

这一修正的清单:

<?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> 

没有更好的结果。

任何想法我可能会丢失?或者我如何能够捕捉到日历报警发生任何其他的想法?

谢谢,阮经天

android calendar broadcast
5个回答
1
投票

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

话虽这么说,至少,你需要一个<data>元素添加到您的<intent-filter>,因为IntentUri

不过,我相当肯定,这是行不通的,因为Intent还专门标识组件(com.android.calendar/.AlertReceiver)。据我所知,这是在一开始就Intent,因此Intent才会投放到该组件,忽略所有其他路由规则。这是可以想象的上市部件后,才Intent分辨率露面了,但我不认为这是那些日志条目是如何工作的。


6
投票

你需要数据的方案设置在意图过滤“内容”。

使用清单,加上意向过滤器内部数据元素

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

使用代码,在一个函数调用添加datascheme

IntentFilter filter = new IntentFilter(CalendarContract.ACTION_EVENT_REMINDER);
filter.addDataScheme("content");   // this was missing
registerReceiver(myRemindersReceiver, filter);

0
投票

有可能通过与你的意图action.You需要指定DataAuthority为“com.android.calendar”和DataScheme为“沿着你的意图,滤波器确定DataAuthority和DataScheme使广播意图“android.intent.action.EVENT_REMINDER”工作内容”。


0
投票

广播意图“android.intent.action.EVENT_REMINDER”只有被炒鱿鱼报警通知需要张贴的提醒时


0
投票

设置通知您事件(例如:在活动开始前10分钟),以便广播意图“android.intent.action.EVENT_REMINDER”工作

© www.soinside.com 2019 - 2024. All rights reserved.