【问题标题】:Android - Open app at specific time dailyAndroid - 每天在特定时间打开应用程序
【发布时间】:2020-03-24 08:08:44
【问题描述】:

我有一个基于套接字的应用程序推送到应用程序,以打开并向用户显示关键工作,例如在商店接收订单。 我要求每天在商店上线前 10 分钟发出警报。 我决定继续使用 AlarmManager,如下所示

Calendar alarmFor = Calendar.getInstance();
alarmFor.set(Calendar.HOUR_OF_DAY, 7);
alarmFor.set(Calendar.MINUTE, 45);
alarmFor.set(Calendar.SECOND, 0);

Intent MyIntent = new Intent(getApplicationContext(), BroadcastNotification.class);
PendingIntent MyPendIntent = PendingIntent.getBroadcast(getApplicationContext(), 0, 
MyIntent, PendingIntent.FLAG_CANCEL_CURRENT);

AlarmManager MyAlarm = (AlarmManager) getSystemService(ALARM_SERVICE);
MyAlarm.setAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, alarmFor.getTimeInMillis(), 
MyPendIntent);

然后在 onRecieve() 将打开应用程序,如下所示

@Override
public void onReceive(Context context, Intent intent) {
Log.d("MyAPP", "onReceive() called");
// -> open app activity with alarm sound 
}

但上述解决方案似乎很老套。

我还尝试使用 WorkManager OneTimeRequest 在特定时间设置和触发作业。 但是Android Daily Job-Evernote提到WorkManager不保证在特定时间运行,也不保证每天的工作

请您提出更好、统一的方法,保证在特定时间打开应用。

提前致谢。

【问题讨论】:

    标签: android alarmmanager job-scheduling android-workmanager


    【解决方案1】:

    AlarmManager 也不起作用。打盹模式可以防止它(或者更确切地说,它会关闭,但可能会迟到 15 分钟)。你有两个选择:

    1) 不要使用 websocket。使用 FCM。 FCM 允许您发送将唤醒设备的高优先级推送消息。

    2) 让用户将您的打盹模式列入白名单。这不能以编程方式完成(您最多只能启动首选项页面来执行此操作)。这必须由用户手动完成。

    如果你想要一个端到端的系统,我真的建议 #1。 #2 并且要求用户在应用程序之外做一些事情总是有点不确定,很多用户不会这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-01
      • 1970-01-01
      • 2018-12-08
      • 2014-06-19
      • 1970-01-01
      • 2013-03-08
      • 2019-06-30
      • 2011-03-05
      相关资源
      最近更新 更多