我想编写一个应用程序,只要用户1触摸应用程序中的“蜂鸣按钮”, 用户2的电话立即振动。 我已经编写了应用程序代码,并且当用户1单击按钮时,请求将通过post方法和数据库更新发送到服务器。 因此我可以将振动请求发送给服务器。 但是我应该怎么做才能迫使应用程序始终侦听服务器,当服务器发送请求时,手机会振动。 如果您推荐任何其他方式,请与我分享! 我还需要将嗡嗡声历史记录存储在SQL中
答案 0 :(得分:0)
要手动处理后台进程,请使用Service: https://developer.android.com/guide/components/services
当事件发生时,使用Broadcast :(将事件发送到其他Fragment / Activity / Application) https://developer.android.com/guide/components/broadcasts
收听广播事件将其注册到接收器: https://developer.android.com/reference/android/content/BroadcastReceiver
JobScheduler也可以在现代android应用程序中使用: https://developer.android.com/reference/android/app/job/JobScheduler