Android Gps问题

时间:2015-05-14 13:06:45

标签: android gps

以下代码适用于某些设备,但不适用于其他设备。如果我检查gps设置,则gps已打开并提供模拟位置。我的清单文件也作为以下权限:

// Getting LocationManager object
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);        

    // Creating an empty criteria object
    Criteria criteria = new Criteria();

    // Getting the name of the provider that meets the criteria
    provider = locationManager.getBestProvider(criteria, false);

    if(provider!=null && !provider.equals("")){

        // Get the location from the given provider 
        Location location = locationManager.getLastKnownLocation(provider);

        locationManager.requestLocationUpdates(provider, 20000, 1, this);


        if(location!=null)
            onLocationChanged(location);
        else
            Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();

    }else{
        Toast.makeText(getBaseContext(), "No Provider Found", Toast.LENGTH_SHORT).show();
    }

0 个答案:

没有答案