Vis*_*ngh 1 android broadcastreceiver
我创建了一个生日提醒应用程序.我想在晚上12点开始服务,以扫描数据库中的人的生日.我添加了一个广播接收器.
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED"/>
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
但它不起作用.我不是为什么..这里是广播接收器的代码.....
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"));
}
}
Run Code Online (Sandbox Code Playgroud)
我希望在日期更改时执行此代码.请帮我.我需要这个来完成我的应用程序.谢谢...
Gau*_*tam 18
- 在Manifest中创建接收器
<receiver android:name=".MyReceiver" >
<intent-filter>
<action android:name="android.intent.action.DATE_CHANGED" />
</intent-filter>
</receiver>
Run Code Online (Sandbox Code Playgroud)
- 创建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");
}
}
}
Run Code Online (Sandbox Code Playgroud)
100%工作
| 归档时间: |
|
| 查看次数: |
3284 次 |
| 最近记录: |