Android设备Geofence功能失效,寻求技术解决方案
Android端Geofence功能完全失效,iOS端正常运行
我正在开发一款支持iOS和Android的应用,核心功能是借助Geofence判断玩家是否处于球场区域,触发进入/离开事件后调用API记录状态。目前该功能在iOS设备上运行正常,但Android设备上完全无法触发任何Geofence事件。
我的实现逻辑参照Geofence Class示例编写,以下是具体的GeofenceListenerImpl实现代码:
public class GeofenceListenerImpl implements GeofenceListener { public static String API = "https://xxxxxx.com/xxxxxx/"; @Override public void onExit(String id) { Display.getInstance().callSerially(() -> { String textID =id; String username, courtID, primaryCourt, primaryCourtText, userNickName, courtName ; ConnectionRequest courtExitRequest = new ConnectionRequest(); // Format ID ---> (USERNAME)___COURT___(PRIMARYCOURT 0=false 1 = true) username = textID.substring(0,textID.indexOf("___")); textID = textID.substring(textID.indexOf("___")+3); courtID = textID.substring(0,textID.indexOf("___")); textID = textID.substring(textID.indexOf("___")+3); primaryCourtText = textID.substring(0,textID.indexOf("___")); primaryCourt = (primaryCourtText.trim().contains("1")) ? "true" : "false" ; textID = textID.substring(textID.indexOf("___")+3); courtName = textID.substring(0,textID.indexOf("___")); textID = textID.substring(textID.indexOf("___")+3); userNickName = textID.trim(); Date now = new Date(System.currentTimeMillis()); courtExitRequest.setUrl(API + "xxxxxxxxx/playeroutcourt"); courtExitRequest.setPost(false); courtExitRequest.addArgument("username", username); courtExitRequest.addArgument("courtid", courtID); courtExitRequest.addArgument("isprimarycourt", primaryCourt); courtExitRequest.addArgument("timeStamp", now.toString()); courtExitRequest.setFailSilently(true); NetworkManager.getInstance().addToQueue(courtExitRequest); if (Display.getInstance().isMinimized()) { LocalNotification n = new LocalNotification(); n.setId("geo-Exit-01"); n.setAlertBody("Great job out there. Wishing you all the best!"); n.setAlertTitle("See you later " + userNickName); n.setAlertSound("/notification_sound_beep-01a.mp3"); // alert sound file name must begin with notification_sound Display.getInstance().scheduleLocalNotification( n, System.currentTimeMillis() + (60 * 1000), // fire date/time LocalNotification.REPEAT_NONE // Whether to repeat and what frequency ); } else { WP_message.generalMessage("\uE766", "See you later " + userNickName + "\n\n" + "Great job out there. Wishing you all the best!"); } }); } @Override public void onEntered(String id) { Display.getInstance().callSerially(() -> { String textID = id; String username, courtID, primaryCourt, primaryCourtText, userNickName, courtName ; ConnectionRequest courtExitRequest = new ConnectionRequest(); // Format ID ---> (USERNAME)___COURT___(PRIMARYCOURT 0=false 1 = true) username = textID.substring(0,textID.indexOf("___")); textID = textID.substring(textID.indexOf("___")+3); courtID = textID.substring(0,textID.indexOf("___")); textID = textID.substring(textID.indexOf("___")+3); primaryCourtText = textID.substring(0,textID.indexOf("___")); primaryCourt = (primaryCourtText.trim().contains("1")) ? "true" : "false" ; textID = textID.substring(textID.indexOf("___")+3); courtName = textID.substring(0,textID.indexOf("___")); textID = textID.substring(textID.indexOf("___")+3); userNickName = textID.trim(); Date now = new Date(System.currentTimeMillis()); courtExitRequest.setUrl(API + "xxxxxxxxx/playerincourt"); courtExitRequest.setPost(false); courtExitRequest.addArgument("username", username); courtExitRequest.addArgument("courtid", courtID); courtExitRequest.addArgument("isprimarycourt", primaryCourt); courtExitRequest.addArgument("timeStamp", now.toString()); courtExitRequest.setFailSilently(true); NetworkManager.getInstance().addToQueue(courtExitRequest); if (Display.getInstance().isMinimized()) { LocalNotification n = new LocalNotification(); n.setId("geo-Entered-01"); n.setAlertBody( userNickName + "! Good luck with your games!"); n.setAlertTitle("Welcome to " + courtName); n.setAlertSound("/notification_sound_beep-01a.mp3"); // alert sound file name must begin with notification_sound Display.getInstance().scheduleLocalNotification( n, System.currentTimeMillis() + (60 * 1000), // fire date/time LocalNotification.REPEAT_NONE // Whether to repeat and what frequency ); } else { WP_message.generalMessage("\uEA22", "Welcome to " + courtName + "\n\n" + userNickName + "! Good luck with your games!"); } }); } }
我已经尝试过调整Android的权限配置,包括动态权限提示和清单文件中的权限声明,但问题依然存在。希望能得到相关技术帮助,排查Android端Geofence失效的原因。
内容的提问来源于stack exchange,提问作者Oscar Naranjo
相关产品推荐
相关产品推荐

