Java I';我得到了一个GnssLocationProvider:&x27;收购Wakelock';其次是';Wakelock已释放';我的android studio应用程序出现logcat错误

Java I';我得到了一个GnssLocationProvider:&x27;收购Wakelock';其次是';Wakelock已释放';我的android studio应用程序出现logcat错误,java,android,maps,wakelock,Java,Android,Maps,Wakelock,我正在尝试构建一个应用程序,谷歌地图会在登录页上放大你的当前位置。这已经在一个模拟器上运行,然后突然停止并显示错误消息。然后我换了一部android手机,起初工作正常,但现在我得到了一个GnssLocationProvider:“通过发送消息获取Wakelock”,然后是“通过处理消息释放Wakelock”错误,并且找不到修复它的位置,或者代码是否有问题。代码如下: package com.example.mappractise; import androidx.annotation.Requ

我正在尝试构建一个应用程序,谷歌地图会在登录页上放大你的当前位置。这已经在一个模拟器上运行,然后突然停止并显示错误消息。然后我换了一部android手机,起初工作正常,但现在我得到了一个GnssLocationProvider:“通过发送消息获取Wakelock”,然后是“通过处理消息释放Wakelock”错误,并且找不到修复它的位置,或者代码是否有问题。代码如下:

package com.example.mappractise;

import androidx.annotation.RequiresApi;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;

import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Build;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.io.IOException;
import java.util.List;
公共类MapsActivity扩展了FragmentActivity在MapReadyCallback上的实现{

private static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1;
LocationManager locationManager;
private GoogleMap mMap;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);
    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    mapFragment.getMapAsync(this);
    locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
            && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
        // TODO: Consider calling
        //    ActivityCompat#requestPermissions
        // here to request the missing permissions, and then overriding
        //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
        //                                          int[] grantResults)
        // to handle the case where the user grants the permission. See the documentation
        // for ActivityCompat#requestPermissions for more details.
        return;
    }else {
        ActivityCompat.requestPermissions(this,
                new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION},
                PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION);
    }

    System.out.println("Getting to line 53");

    //check if network provide is enabled
    if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, new LocationListener() {
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onLocationChanged(Location location) {
                //get latitude
                double latitude = location.getLatitude();
                //get longitude
                double longitude = location.getLongitude();
                //instantiate the class LatLng
                LatLng latLng = new LatLng(latitude, longitude);
                //instantiate the class, geocoder
                Geocoder geocoder = new Geocoder(getApplicationContext());
                try {
                    List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
                    String str = addressList.get(0).getLocality();
                    str += addressList.get(0).getCountryName()+",";
                    mMap.addMarker(new MarkerOptions().position(latLng).title(str));
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15.2f));

                    int num = 0;
                    do {
                        System.out.println("Count : "+num);
                        System.out.println("Latitude : " + latitude);
                        System.out.println("Longitude : " + longitude);
                        System.out.println("Time : "+java.time.LocalTime.now());
                        Thread.sleep(1000);
                        num++;
                        if(num==11){
                            break;
                        }

                    } while (num<=10);
                System.out.println("Loop Finished");

                } catch (IOException | InterruptedException e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {

            }
        });
    } else if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                //get latitude
                double latitude = location.getLatitude();
                //get longitude
                double longitude = location.getLongitude();
                //instantiate the class LatLng
                LatLng latLng = new LatLng(latitude, longitude);
                //instantiate the class, geocoder
                Geocoder geocoder = new Geocoder(getApplicationContext());
                try {
                    List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
                    String str = addressList.get(0).getLocality();
                    str += addressList.get(0).getCountryName()+",";
                    mMap.addMarker(new MarkerOptions().position(latLng).title(str));
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10.2f));
                } catch (IOException e) {
                    e.printStackTrace();
                    System.out.println("Error above line 129");
                }
            }

            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {

            }
        });
    }


}


/**
 * Manipulates the map once available.
 * This callback is triggered when the map is ready to be used.
 * This is where we can add markers or lines, add listeners or move the camera. In this case,
 * we just add a marker near Sydney, Australia.
 * If Google Play services is not installed on the device, the user will be prompted to install
 * it inside the SupportMapFragment. This method will only be triggered once the user has
 * installed Google Play services and returned to the app.
 */
@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;

    // Add a marker in Sydney and move the camera
    //LatLng sydney = new LatLng(-34, 151);
    //mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    //mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
private static final int PERMISSIONS\u REQUEST\u ACCESS\u FINE\u LOCATION=1;
地点经理地点经理;
私有谷歌地图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_映射);
//获取SupportMapFragment,并在地图准备好使用时收到通知。
SupportMapFragment mapFragment=(SupportMapFragment)getSupportFragmentManager()
.findFragmentById(R.id.map);
getMapAsync(这个);
locationManager=(locationManager)getSystemService(位置服务);
if(ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS\u FINE\u LOCATION)!=PackageManager.permission\u已授予
&&ActivityCompat.checkSelfPermission(此,Manifest.permission.ACCESS\u\u位置)!=PackageManager.permission\u已授予){
考虑到呼叫
//ActivityCompat#请求权限
//在此处请求缺少的权限,然后覆盖
//public void onRequestPermissionsResult(int-requestCode,字符串[]权限,
//int[]格兰特结果)
//处理用户授予权限的情况。请参阅文档
//对于ActivityCompat,请请求权限以获取更多详细信息。
返回;
}否则{
ActivityCompat.requestPermissions(此,
新字符串[]{android.Manifest.permission.ACCESS\u FINE\u LOCATION},
权限(请求、访问、位置);
}
System.out.println(“到达第53行”);
//检查网络提供是否已启用
if(locationManager.isProviderEnabled(locationManager.NETWORK_PROVIDER)){
locationManager.RequestLocationUpdate(locationManager.NETWORK_提供程序,0,0,新LocationListener(){
@RequiresApi(api=Build.VERSION\u CODES.O)
@凌驾
已更改位置上的公共无效(位置){
//获得自由
双纬度=location.getLatitude();
//获得经度
double longitude=location.getLongitude();
//实例化类LatLng
LatLng LatLng=新LatLng(纬度、经度);
//实例化类geocoder
Geocoder Geocoder=新的Geocoder(getApplicationContext());
试一试{
List addressList=geocoder.getFromLocation(纬度、经度,1);
String str=addressList.get(0.getLocality();
str+=addressList.get(0.getCountryName()+”,”;
mMap.addMarker(新的MarkerOptions().position(latLng).title(str));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,15.2f));
int num=0;
做{
System.out.println(“计数:+num”);
System.out.println(“纬度:”+纬度);
System.out.println(“经度:”+经度);
System.out.println(“Time:+java.Time.LocalTime.now());
睡眠(1000);
num++;
如果(num==11){
打破
}

}而(numIf)如果您看到消息的日志级别,它们会被标记为“信息”的日志级别-这些消息不是警告或错误,因此可以忽略,因为这些消息只记录信息。谢谢,这很有帮助,我只是将它们过滤掉了