所以我试着在我的安卓应用程序中实现这个站点的重复功能-- 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
发布于 2012-12-30 13:04:29
解决方案是采取以下措施:
//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();
}
}并将其另存为RepeatingAlarm.java,基本上它是自己的类。然后进入mainfest文件并添加一些这样的效果
<receiver android:name="RepeatingAlarm"></receiver>https://stackoverflow.com/questions/14087868
复制相似问题