我想为我的Android应用开发提醒返回功能。我希望从用户不使用应用程序的一天过后,我会显示本地通知,提醒用户“我们还有更多新内容,请触摸此处以阅读新内容”。
但是我不知道如何编码。
我不知道如何检测应用程序是从后台开始的(onPause可以在应用程序进入后台时触发,也可以在应用程序更改活动时触发)。
当应用在后台运行时,如何触发通知。我有此功能来显示通知,但在调用它后会显示。我该如何延迟一天。
显示通知()
NotificationManager notificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.down_icon, getString(R.string.press_back_again_if_you_want_to_exit_app), System.currentTimeMillis());
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
notification.setLatestEventInfo(this, this.getString(R.string.press_back_again_if_you_want_to_exit_app),
this.getString(R.string.press_back_again_if_you_want_to_exit_app), pendingIntent);
notificationManager.notify(1, notification);
我在iOS中开发功能非常容易,但是在Android中,我不知道该怎么做。
最佳答案
要满足您的要求,请执行以下步骤。
步骤1-当您的应用启动时,启动后台服务。在服务中,每个时间间隔检查最活跃的活动
步骤2:在最活跃的活动不属于您的应用程序时进入服务状态,然后安排警报在24小时后触发并破坏服务。