首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Android告警未触发

Android告警未触发
EN

Stack Overflow用户
提问于 2011-01-20 21:06:46
回答 1查看 633关注 0票数 0

我确信这是很简单的事情,但我没有弄明白。我正在试着做一个简单的重复闹钟,但它永远不会被触发。我得到的是:

代码语言:javascript
复制
private void setupAlarms()
{
    AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);

    Intent intent = new Intent(this, RepeatingAlarm.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(HelloAndroid.this, 0, intent, 0);

    GregorianCalendar fifteenSeconds = (GregorianCalendar)Calendar.getInstance();
    fifteenSeconds.add(Calendar.MINUTE, 0);
    fifteenSeconds.set(Calendar.SECOND, 15);

    alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
            SystemClock.elapsedRealtime(), fifteenSeconds.getTimeInMillis(), pendingIntent);
}

这是从主onCreate调用中调用的。

我的闹钟接收器:

代码语言:javascript
复制
public class RepeatingAlarm extends BroadcastReceiver
{
    @Override
    public void onReceive(Context context, Intent intent)
    {
        Toast.makeText(context, R.string.hello, Toast.LENGTH_SHORT).show();
    }
}

在我的清单中,我添加了:

代码语言:javascript
复制
<receiver android:name=".RepeatingAlarm" android:process=":remote" />

如有任何帮助,非常感谢

EN

回答 1

Stack Overflow用户

发布于 2011-01-20 21:42:46

你给你的BroadcastReceiver添加了意图过滤器了吗?在您的AndroidManifest.xml文件中,代码可能如下所示:

代码语言:javascript
复制
    <receiver android:name=".RepeatingAlarm" android:exported="true">
        <intent-filter>
            <action android:name="intent id text" />
        </intent-filter>
    </receiver>

当创建你的意图时,要这样做:

代码语言:javascript
复制
Intent intent = new Intent("intent id text")

其中"intent id text“可以是你用来识别你的意图的任何字符串。此外,如果你重启你的设备,Android的警报会被重置,所以这可能是你需要考虑的事情。

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4747481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档