我创建了一个生日提醒应用程序。我想在晚上 12:00 开始服务来扫描数据库中人员的生日。我添加了一个广播接收器。
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED"/>
</intent-filter>
</receiver>
但它不起作用。我不明白为什么..
这是广播接收器的代码......
package com.example.forgetmenot;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context arg0, Intent arg1) {
Toast.makeText(arg0, "BroadCast Receiver", Toast.LENGTH_SHORT).show();
arg0.startService(new Intent("com.example.forgetmenot.BirthdayService"));
}
}
我想在日期更改时执行此代码。请帮我。我需要这个来完成我的应用程序。谢谢...
- 在清单中创建接收者
<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" />
</intent-filter>
</receiver>
- 创建广播接收器类
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_DATE_CHANGED)) {
Log.e("", "ACTION_DATE_CHANGED received");
}
}
}
100% 工作
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)