android 如何为手机设置虚假位置
我尝试对手机使用模拟位置,但它显示异常,
我的代码如下,
Location location = new Location(MOCK_PROVIDER_NAME);
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setTime(new Date().getTime());
locationManager.setTestProviderEnabled(MOCK_PROVIDER_NAME, true);
locationManager.setTestProviderLocation(MOCK_PROVIDER_NAME, location);
Toast.makeText(getBaseContext(),"Latitude: "+location.getLatitude()+" Longitude: "+location.getLongitude(), Toast.LENGTH_SHORT)
.show();
我给了 MOCK_PROVIDER_NAME=“gps”,但这一个也没有采用,我也尝试过“网络”和“欺骗”,但它不起作用。
我哪里出错了,请任何人告诉我。 谢谢
I trying to use Mock location to the phone but it showing exceptions,
my code is below,
Location location = new Location(MOCK_PROVIDER_NAME);
location.setLatitude(latitude);
location.setLongitude(longitude);
location.setTime(new Date().getTime());
locationManager.setTestProviderEnabled(MOCK_PROVIDER_NAME, true);
locationManager.setTestProviderLocation(MOCK_PROVIDER_NAME, location);
Toast.makeText(getBaseContext(),"Latitude: "+location.getLatitude()+" Longitude: "+location.getLongitude(), Toast.LENGTH_SHORT)
.show();
i gave MOCK_PROVIDER_NAME= "gps" but this one is not taking also i tried with "network" and "spoof" , but its not working.
Where i am going wrong, plz anybody tell me.
Thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下是导致您的问题的两个可能原因:
安全异常:
或 IllegalArgumentException:
我会从以下位置获取这些引用: http: //developer.android.com/reference/android/location/LocationManager.html#addTestProvider
如果这不是您收到的异常之一,请向我们提供错误的堆栈跟踪以及任何行堆栈跟踪显示在您的代码中是问题所在。
我猜您没有在清单中声明权限和/或“允许模拟位置”在开发设置中处于关闭状态。
Here are two possible causes of your issue:
a security exception:
Or IllegalArgumentException:
I got those quotes from: http://developer.android.com/reference/android/location/LocationManager.html#addTestProvider
If it's not one of those to Exceptions that you are getting, then give us the stack trace of your error as well as whatever line the stack trace shows in your code is the issue.
I'm GUESSING you didn't declare the permission in manifest AND/OR "Allow Mock Locations" is off in the development settings.