问题描述
我的目标是使用AlarmManager与绑定的前台服务同步数据,以在打开应用程序时显示进度对话框,否则显示通知
我没有警报管理器就可以正常工作,但是我不知道如何使用如下所示的未决意图来绑定服务
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
manualSyncServiceListener = new OManualSyncService.OManualSyncServiceListener();
syncingServiceIntent = new Intent(this,OManualSyncService.class);
if(bound){
oManualSyncService.setListener(null); // unregister
unbindService(serviceConnection);
bound = false;
}
long frequency = 15000;
PendingIntent pendingIntent = PendingIntent.getService(this,REQUEST_AUTOMATIC_SYNC,syncingServiceIntent,0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
alarmManager.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,System.currentTimeMillis() + frequency,pendingIntent);
}
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
alarmManager.setExact(AlarmManager.RTC_WAKEUP,frequency,pendingIntent);
}
else {
alarmManager.set(AlarmManager.RTC_WAKEUP,pendingIntent);
}
我需要这样的东西
bindService(pendingIntent,serviceConnection,Context.BIND_AUTO_CREATE);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)