Geofencing Example Google API
您可以在添加地理栅栏对象时设置expirationDurationTime.
如何在AndroID中设置启动Geofence Monitoring的时间?
例:
我希望明天14:30到15:30在“abc”位置进行地理围栏监测,并进行“xyz”地理围栏循环
我没有找到谷歌地理围栏API提供的任何功能,我可以设置开始监控地理围栏对象的时间.
请帮我.我现在非常绝望:(
更新
从@Pavneet_Singh的帖子中读到WorkManager之后
我仍然混淆如何在这里组合WorkManager,因为我已经使用IntentService扩展了我的类,以便从Location.Service获得意图.
公共类GeofenceTransitionsIntentService扩展IntentService {
private final String TAG = "GeofenceTransIntServ";/** * Creates an IntentService. Invoked by your subclass's constructor. * * @param name Used to name the worker thread,important only for deBUGging. */public GeofenceTransitionsIntentService(String name) { super(name);}/** * This method is invoked on the worker thread with a request to process. * Only one Intent is processed at a time,but the processing happens on a * worker thread that runs independently from other application logic. * So,if this code takes a long time,it will hold up other requests to * the same IntentService,but it will not hold up anything else. * When all requests have been handled,the IntentService stops itself,* so you should not call {@link #stopSelf}. * * @param intent The value passed to {@link * Context#startService(Intent)}. * This may be null if the service is being restarted after * its process has gone away; see * {@link Service#onStartCommand} * for details. */@OverrIDeprotected voID onHandleIntent(@Nullable Intent intent) { GeofencingEvent geofencingEvent = GeofencingEvent.fromIntent(intent); if (geofencingEvent.hasError()) { String errorMessage = GeofenceErrorMessages.getErrorString(this,geofencingEvent.getErrorCode()); Log.e(TAG,errorMessage); return; } // Get the Transition type. int geofenceTransition = geofencingEvent.getGeofenceTransition(); // Test that the reported Transition was of interest. if (geofenceTransition == Geofence.GEOFENCE_Transition_ENTER || geofenceTransition == Geofence.GEOFENCE_Transition_EXIT) { // Get the geofences that were triggered. A single event can trigger // multiple geofences. List<Geofence> triggeringGeofences = geofencingEvent.getTriggeringGeofences(); // Get the Transition details as a String. String geofenceTransitionDetails = getGeofenceTransitionDetails( geofenceTransition,triggeringGeofences ); // Send notification and log the Transition details. sendNotification(geofenceTransitionDetails); Log.i(TAG,geofenceTransitionDetails); } else { // Error }}private voID sendNotification(String geofenceTransitionDetails) { // send notification}/** * Gets Transition details and returns them as a formatted string. * * @param geofenceTransition The ID of the geofence Transition. * @param triggeringGeofences The geofence(s) triggered. * @return The Transition details formatted as String. */private String getGeofenceTransitionDetails( int geofenceTransition,List<Geofence> triggeringGeofences) { String geofenceTransitionString = getTransitionString(geofenceTransition); // Get the IDs of each geofence that was triggered. ArrayList<String> triggeringGeofencesIDsList = new ArrayList<>(); for (Geofence geofence : triggeringGeofences) { triggeringGeofencesIDsList.add(geofence.getRequestID()); } String triggeringGeofencesIDsstring = TextUtils.join(",",triggeringGeofencesIDsList); return geofenceTransitionString + ": " + triggeringGeofencesIDsstring;}private String getTransitionString(int geofenceTransition) { // get the TransitionType as String return null;}
}
我的想法 :
将GeofenceTransitionsIntentService中的notificationMessage传递给另一个从Worker扩展的类,并使用setinitialdelay方法推迟通知?
我发现有人用JobIntentService扩展了GeofenceTransitionsIntentService类,但我认为我不能用JobIntentService扩展我的类,因为JobIntentService不提供延迟功能.
我怎么能让它现在起作用,我是否正确思考?
谢谢
@H_404_4@解决方法 您实际上是在询问在某个特定时间触发的警报机制.有很多选项可以做到这一点
最优方案:
> WorkManager
> JobScheduler
其他(由于Naught,Oreo的背景限制)
>报警
有了上述功能,您可以在特定时间开始执行任务
参考文献:
Schedule a work on a specific time with WorkManager
how to do something at specific time for everyday in android
@H_404_4@ @H_404_4@ @H_404_4@ @H_404_4@ 总结以上是内存溢出为你收集整理的android – 设置监控地理围栏的开始时间全部内容,希望文章能够帮你解决android – 设置监控地理围栏的开始时间所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)