0
上沒有調用的鬧鐘所以我試圖從這個網站實現重複功能 - http://www.java2s.com/Code/Android/Core-Class/Exampleofschedulingoneshotandrepeatingalarms.htm - 進入我的Android應用程序,但由於某些原因,它沒有調用該類,這裏是代碼摘錄。Android
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
接收器是否在清單中聲明? –
那肯定就是這樣,因爲這跟谷歌示例中的代碼基本相同。我猜這是 會修復它嗎? –
eWizardII
如果這是你的接收器的位置是的(所以如果你有一個實際的子包叫做接收器,那裏有你的RepeatingAlarm類)。 –