Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在屏幕锁定时启动gps_Android_Locking_Screen_Latitude Longitude - Fatal编程技术网

Android 在屏幕锁定时启动gps

Android 在屏幕锁定时启动gps,android,locking,screen,latitude-longitude,Android,Locking,Screen,Latitude Longitude,我开发了一个应用程序,使用广播接收器获取纬度值。它工作得很好,但每当屏幕被锁定时,我就得不到任何值。但如果我解锁屏幕,我会得到值。有人愿意帮我解决问题吗?在你的清单文件中试试这个,可能会有帮助。我也不确定。试一下 android:configChanges="orientation|keyboard|keyboardHidden" android:launchMode="singleInstance" 确保你在“暂停”的方法中没有做任何奇怪的事情,在我的情况下,我很生气

我开发了一个应用程序,使用广播接收器获取纬度值。它工作得很好,但每当屏幕被锁定时,我就得不到任何值。但如果我解锁屏幕,我会得到值。有人愿意帮我解决问题吗?

在你的清单文件中试试这个,可能会有帮助。我也不确定。试一下

android:configChanges="orientation|keyboard|keyboardHidden"
            android:launchMode="singleInstance"

确保你在“暂停”的方法中没有做任何奇怪的事情,在我的情况下,我很生气,因为屏幕被锁定时GPS停止工作,这是因为在“暂停”的方法中,我从位置管理器中删除了更新。

当手机进入深度睡眠模式时,即屏幕关闭几分钟后,GPS停止。 您需要在想要获取GPS更新的时间段内获取唤醒锁

PowerManager powerManager = (PowerManager) context.getSystemService(context.POWER_SERVICE);
            wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "WakeLock");
            wakeLock.acquire();
完成后,释放锁

wakeLock.release();

请参见

Android是否有水晶球?@mitch Wheat no Crystal Ball您如何知道自己没有获得位置值?是否在任何位置显示位置值?请尝试使用
WakeLock
。并尝试使用
服务
而不是
广播接收器