手机重启后恢复报警经理 [英] Restore Alarm manager after phone reboot
问题描述
我建立一个小部件用于学习目的,它只是在那里我设定的更新间隔的配置活动。它工作正常,我可以创建它的多个实例。
但是当我重新启动报警经理停止电话,部件将不会更新。
某些搜索和google'ng后,我知道我必须添加一个BOOT完整的接收
但几次尝试后,我没有执行,因此任何人都有关于如何添加或部件的任何良好来源$ C $ C例如一个我的想法。
i am building a small widget for learning purpose, it simply has an configuration activity where i set the update interval. it works normally and i can create multiple instance of it. but when i reboot the phone the alarm manager stops, and the widget won't update. after some search and google'ng i learned that i have to add a BOOT COMPLETE receiver but after several attempts i failed to implement so any one has an i idea about how to add that or any good source code example on widgets.
推荐答案
要做到在启动一些你根本看下面。
To do something at boot you simply do following.
首先在清单
,这是正在申请加入标签:
First in the manifest
, this is added under application tag:
<receiver android:name="AlarmReceiver">
<intent-filter>
<action android:name="packagename.ACTION"/>
<action android:name="packagename.ACTION2"/>
</intent-filter>
</receiver>
<receiver android:name="BootSetter" >
<intent-filter>
<action
android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
为了这个工作,你需要添加允许接收广播在清单与以下行:
In order for this to work you need to add permission to receive the Broadcast in the manifest with following line:
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
然后你有一个类BootSetter:
Then you have a class BootSetter:
public class BootSetter extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Do your stuff
}
}
有一个类似的帖子,虽然不是完全地相同的这里。这是关于运行每天中午报警。
There is a similar post, though not completly the same here. It's about running an alarm every day at noon.
这篇关于手机重启后恢复报警经理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!