且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

手机重启后恢复报警经理

更新时间:2023-02-02 17:41:31

要做到在启动一些你根本看下面。

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.