我创建了一个生日提醒应用程序。我想在晚上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>
- 创建BroadcastReceiver类
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%工作
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句