我创建了一个应用程序,轮询服务器以获取必须发送给我们用户的短信。对于轮询功能,我已经使用了报警经理解雇每5分钟轮询服务器Android闹钟管理器不能在三星Galaxy手机上工作
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");
}
我已经测试了针对2.2构建模拟器的应用,一切工作正常,现在测试最终出来的短信会我已经在三星Galaxy S手机上安装了该应用程序。
一旦安装了应用程序,并且选择了轮询服务器的优先选项,则什么都不会发生。
可能是什么问题
我有问题(许多! )在三星Galaxy S设备中,在这种情况下,我遇到了读取默认共享prefs的问题,并在logcat中看到以下日志消息 - 您是否也看到了这一点?“W/ApplicationContext(4563):尝试阅读 首选项文件/dbdata/databases/.../ shared_prefs /..._ preferences.xml没有 权限“ 此外,我发现一些引用这只bei在2.2.1上有问题 - 你在什么版本上? – DustinB 2011-01-25 20:19:39