Android alarm manager not working on Samsung Galaxy phone
I have created an app which polls a server to fetch SMS that have to be sent to our users. For the polling functionality i have used the alarm manager to fire every 5 min to poll server
AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent pintent = new Intent(this, SMSSender.class);
PendingIntent pIntent = PendingIntent.getBroadcast(this,0,pintent, 0);
if(checkbox.isChecked()) {
long interval = 60*Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString("pref_poll_interval", "5000"));//5mins;//5mins
long firstPoll = SystemClock.elapsedRealtime() + 60*Integer.valueOf(PreferenceManager.getDefaultSharedPreferences(this).getString("pref_开发者_运维百科poll_interval", "5000"));
alarm.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstPoll, interval, pIntent);
Log.d("SMS_GATEWAY", "alarm manager turned on "+interval);
}else {
alarm.cancel(pIntent);
Log.d("SMS_GATEWAY", "alarm manager turned off");
}
I have tested the application on the emulator against the 2.2 build and everything works fine, now test the final out of SMS going out i have installed the app on a Samsung Galaxy S phone.
Once the app is installed and the preference to poll server is selected, nothing really happens.
What could be the problem
Consider using the BuzzBox SDK library for your problem.
http://hub.buzzbox.com/android-sdk/
You can schedule a task using a cron string:
SchedulerManager.getInstance()
.saveTask(this, "*/5 8-19 * * 1,2,3,4,5", YourTask.class);
I have a Galaxy S and I'm using the BuzzBox SDK in a few of my apps. You can check the scheduler log integrated in the SDK to verify that your Task is running properly.
AlarmManager is not working correctly on Samsung phones in deep sleep :( BuzzBox SDK use AlarmManager so it has the same problem (I tested on Galaxy 5500). For example http://www.netzpurist.de/2010/11/samsung-gt-i5500-with-android-2-1-update1-alarmmanager-not-suitable/
精彩评论