通过eclipse重新安装apk文件后,getlastknownlocation总是返回null
问题描述
最近,我创建了一个简单的应用程序来获取 gps 位置并在 android 手机上显示.一开始我尝试几次后就可以得到位置,但是在我重新安装apk文件后,getLastKnownLocation()总是返回一个空值.
Recently, I created a simple application to get the gps location and display on android phone. At beginning I able to get the location after few try, but after i re-install the apk file, the getLastKnownLocation() always return a null value.
使用的开发环境:- API 10 姜饼 2.3.6- 使用 GPS 提供程序
Development environment used: - API 10 gingerbread 2.3.6 - GPS provider is used
下面是我在我的android项目中应用的代码:
below is the code i applied in my android project:
谁能提出一个可能的解决方案来解决 getLastKnownLocation() 返回的空值?任何帮助将不胜感激.谢谢.
Can anyone suggest a possible solution to solve the null value returned by getLastKnownLocation()? Any helps will be appreciated. Thanks.
推荐答案
getLastKnownLocation()
这将返回最后一个已知位置...在您重新安装应用程序后它不会有任何最后一个已知位置...所以它会导致 NPE...而不是使用下面的代码
the getLastKnownLocation()
this returns the last known location...after you re-install the app it will not have any last known location...so it will result in NPE...instead use below code
它对我有用……应该也对你有用……
It worked for me...should work for you too...
这篇关于通过eclipse重新安装apk文件后,getlastknownlocation总是返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!