我开始了解AlarmManager,并且我想触发广播以从服务器获取一些信息。该文档清楚地说明了意图和警报,但我找不到任何关于接收端的外观。这是我的报警代码:AlarmManager aMgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);Intent intent = new Intent(this, AlarmReceiver.class);PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0);aMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + 10000, AlarmManager.INTERVAL_FIFTEEN_MINUTES, pendingIntent);我AlarmReceiver是这样的:public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Log.d(MainActivity.TAG, "Received intent"); }}但什么也没有发生。我添加了一个按钮来触发广播,如下所示:public void btnTrigger_onClick(View view) { Intent i = new Intent(this, AlarmReceiver.class); sendBroadcast(i);}而且这里什么也没有发生。我以前使用过广播,但仅使用registerReceiver,但我不想在Activity现在处理广播。
添加回答
举报
0/150
提交
取消