我有一个应用程序(称为A),该服务运行一个模拟从蓝牙GPS获取的位置的服务,以便在另一个应用程序(称为B)中使用它:
一切都可以在Android 7.0上运行,但是在Android 8.0(Oreo)中,应用程序B不会读取从蓝牙获取的位置,也就是说,我认为这是因为在模拟位置时出现了问题,因为日志始终会打印此内容行:
def OnEraseBackground(self, evt):
"""
Add a picture to the background
"""
# yanked from ColourDB.py
dc = evt.GetDC()
if not dc:
dc = wx.ClientDC(self)
rect = self.GetUpdateRegion().GetBox()
dc.SetClippingRect(rect)
dc.Clear()
w,h = self.GetSize()
bmp = wx.Bitmap("AMD.png")
image = bmp.ConvertToImage()
bmp = wx.Bitmap(image.Scale(w,h))
dc.DrawBitmap(bmp, 0, 0)
我用来模拟位置的代码是:
E PassiveLocationListener_FLP: isFromMockProvider, return
问题是,我没有看到异常打印出来,所以我认为该过程是正确的,但是就像Android出于某种原因我不允许我这样做一样。
我在清单中声明了 private void changeToMockLocation() {
Log.i(TAG, "changeToMockLocation()");
Location newLocation = new Location(PROVIDER_NAME);
newLocation.setLatitude(mNMEAData.getLatitude());
newLocation.setLongitude(mNMEAData.getLongitude());
newLocation.setAccuracy(mNMEAData.getAccuracy());
newLocation.setTime(System.currentTimeMillis());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
newLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
// Set mock location.
if (ActivityCompat.checkSelfPermission(
mContext, android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
try {
mLocationManager.setTestProviderLocation(PROVIDER_NAME, newLocation);
} catch (Exception e) {
Log.e(TAG, "Error while setting test provider location: " + e);
}
}
}
权限,并且允许该应用模拟开发人员设置中的位置。
我在做什么错了?
预先感谢,祝您愉快。
答案 0 :(得分:0)
Oreo的(Samsung?)开发人员设置屏幕中似乎存在一个错误。我还将我的应用设置为模拟提供程序,并在清单中获得了许可。对我来说,问题是通过将应用程序删除为模拟位置提供程序并再次添加回去来解决的:
Developer options -> Mock location app -> No apps
Developer options -> Mock location app -> Your app
尽管如此,我仍然在logcat中看到这些消息:
E/PassiveLocationListener_FLP: isFromMockProvider, return
I/LocationManagerService: remove xxxxxxx
I/LocationManagerService: removeUpdates, receiver.requestedID = xxxxxxx, receiver.mIdentity.mPid = 2908, receiver.mIdentity.mUid = 1000
D/SLocation: removeGpsStatusListener
D/ListenerMonitor_FLP: removeListener, not existed listener android, xxxxxxx in mListenerIdMap
E/RequestManager_FLP: [LocationManagerService] Location remove xxxxxxx from system