Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.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_Android Context_Android Toast - Fatal编程技术网

android Gps代码吐司

android Gps代码吐司,android,android-context,android-toast,Android,Android Context,Android Toast,我制作了一个简单的应用程序来为纬度干杯。我在Nexus5上运行了该代码,但在三星GalaxyS4上运行时,它并没有显示祝酒词。为什么? @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); locationManager = (LocationMan

我制作了一个简单的应用程序来为纬度干杯。我在Nexus5上运行了该代码,但在三星GalaxyS4上运行时,它并没有显示祝酒词。为什么?

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);


     String provider = LocationManager.GPS_PROVIDER;

     locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER,
              500,  
              1, this);         
}

@Override
public void onLocationChanged(Location location) {
    // TODO Auto-generated method stub
    log =   Double.toString(location.getLongitude());   

    lat = Double.toString(location.getLatitude());  

    Toast.makeText(getBaseContext(), lat, Toast.LENGTH_LONG).show();
}

对我来说,它与getApplicationContext()一起工作(活动的成员) 类)


--Gerhard

添加日志/错误跟踪。什么东西不管用?可能您的三星s4设备上的GPS已关闭。@Xry没有错误,GPS已关闭on@Xry-不,Nexus在5.0上,s4在4.4.2Hi sara上,请尝试使用它而不是getBaseContext()。您确定三星s4上是否调用了
onLocationChanged()
?如果不是,则添加日志记录(不是Toast)并检查Logcat。