因此,我正在尝试在我的 Android 应用程序中实现此站点的重复功能 - http://www.java2s.com/Code/Android/Core-Class/Exampleofschedulingoneshotandrepeatingalarms.htm - 但由于某种原因它没有调用该类是代码摘录。
public class MainActivity extends Activity implements SensorEventListener {
// Schedule repeating alarm
Intent intent = new Intent(MainActivity.this, RepeatingAlarm.class);
PendingIntent sender = PendingIntent.getBroadcast(MainActivity.this, 0,
intent, 0);
// We want the alarm to go off 30 seconds from now.
long firstTime = SystemClock.elapsedRealtime();
firstTime += 15 * 1000;
// Schedule the alarm!
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime,
15 * 1000, sender);
// Tell the user about what we did.
Toast.makeText(
getApplicationContext(),
"Scheduled", Toast.LENGTH_LONG)
.show();
}
//Schedule alarm for data upload
class RepeatingAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(
context,
"ALARMED!", Toast.LENGTH_LONG)
.show();
}
}
如果它有帮助,完整的代码在这里:https ://gist.github.com/4410665