我有广播接收器,该广播接收器应安排警报。
通常我会这样做
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.set(AlarmManager.RTC, time, myPendingIntent);
问题是 getSystemService 仅在活动中的广播接收器中不可用。我在这里该怎么做呢?
谢谢。
安迪安卓,
getSystemService()
是的一部分Context
。您需要保存Context
你收到在你的onReceive()
像这样的方法...
private Context mContext;
@Override
public void onReceive(Context c, Intent i) {
mContext = c;
}
然后..你打电话的地方getSystemService()
你用...
AlarmManager am = (AlarmManager) mContext.getSystemService(mContext.ALARM_SERVICE);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)