android 如何为手机设置虚假位置

发布于 2024-12-02 12:54:45 字数 768 浏览 1 评论 0原文

我尝试对手机使用模拟位置,但它显示异常,

我的代码如下,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

樱娆 2024-12-09 12:54:45

以下是导致您的问题的两个可能原因:

安全异常:

如果 ACCESS_MOCK_LOCATION 权限不存在或者
Settings.Secure.ALLOW_MOCK_LOCATION系统设置未启用

或 IllegalArgumentException:

如果具有给定名称的提供程序已存在

我会从以下位置获取这些引用: http: //developer.android.com/reference/android/location/LocationManager.html#addTestProvider

如果这不是您收到的异常之一,请向我们提供错误的堆栈跟踪以及任何行堆栈跟踪显示在您的代码中是问题所在。

我猜您没有在清单中声明权限和/或“允许模拟位置”在开发设置中处于关闭状态。

Here are two possible causes of your issue:

a security exception:

if the ACCESS_MOCK_LOCATION permission is not present or the
Settings.Secure.ALLOW_MOCK_LOCATION system setting is not enabled

Or IllegalArgumentException:

if a provider with the given name already exists

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文