GPS-координаты не отображаются на телефоне, но отображаются на эмуляторе - Android Studio - PullRequest
0 голосов
/ 26 сентября 2019

Я тестирую простое приложение GPS в Android Studio, которое выдает определенные данные о местоположении GPS на экране.Когда я запускаю приложение на эмуляторе, все работает отлично.Однако, когда я подключаю свой телефон и пытаюсь запустить его там, приложение устанавливается и запускается, но данные GPS не отображаются.У меня действительно включены опции разработчика и включена отладка по USB.Я запросил разрешение на местоположение на устройстве.У меня есть Android 8 на моем телефоне.Мой телефон по какой-то причине блокирует поступление данных GPS?

Код:

package com.example.hikersapp;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity {

    LocationManager locationManager;
    LocationListener locationListener;

    //check and see if we got permission to get GPS location of device
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);

//Checking if permission was granted and if it was then call the locationmanager variable to get location
        if (requestCode == 1) {
            if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
                    //This line is the line that actually gets the users location and
                    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
                }
            }
        }
    }

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





        locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        locationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {

                TextView latitudeTextView = (TextView) findViewById(R.id.latitudeTextView);
                TextView longitudeTextView = (TextView) findViewById(R.id.longitudeTextView);
                TextView accuractyTextView = (TextView) findViewById(R.id.accuracyTextView);
                TextView altitudeTextView = (TextView) findViewById(R.id.altitudeTextView);
                TextView addressTextView = (TextView) findViewById(R.id.addressTextView);

                double latitudeCurrent;
                double longitudeCurrent;
                double accuracyCurrent;
                double altitudeCurrent;

                latitudeCurrent = location.getLatitude();
                longitudeCurrent = location.getLongitude();
                accuracyCurrent = location.getAccuracy();
                altitudeCurrent = location.getAltitude();

                latitudeTextView.setText("Latitude: " + String.valueOf(latitudeCurrent));
                longitudeTextView.setText("Longitude: " +String.valueOf(longitudeCurrent));
                accuractyTextView.setText("Accuracy: " + String.valueOf(accuracyCurrent));
                altitudeTextView.setText("Altitude: " + String.valueOf(altitudeCurrent));

            }

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

            }

            @Override
            public void onProviderEnabled(String provider) {

            }

            @Override
            public void onProviderDisabled(String provider) {

            }
        };

        //Asking for permission to get location if it wasn't already provided
        if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
        } else {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
            Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);


        }
    }
}

Pic of running it on my phone Pic of App on Emulator

Logcat:

2019-09-26 14:35:32.791 25133-25133/com.example.hikersapp E/Zygote: isWhitelistProcess - Process is Whitelisted
2019-09-26 14:35:32.792 25133-25133/com.example.hikersapp E/Zygote: accessInfo : 1
2019-09-26 14:35:32.815 25133-25133/com.example.hikersapp I/ample.hikersap: Late-enabling -Xcheck:jni
2019-09-26 14:35:32.889 25133-25133/com.example.hikersapp D/TimaKeyStoreProvider: TimaKeyStore is not enabled: cannot add TimaSignature Service and generateKeyPair Service
2019-09-26 14:35:33.050 25133-25188/com.example.hikersapp D/vndksupport: Loading /vendor/lib64/egl/libEGL_adreno.so from current namespace instead of sphal namespace.
2019-09-26 14:35:33.058 25133-25188/com.example.hikersapp D/libEGL: loaded /vendor/lib64/egl/libEGL_adreno.so
2019-09-26 14:35:33.079 25133-25188/com.example.hikersapp D/vndksupport: Loading /vendor/lib64/egl/libGLESv1_CM_adreno.so from current namespace instead of sphal namespace.
2019-09-26 14:35:33.080 25133-25188/com.example.hikersapp D/libEGL: loaded /vendor/lib64/egl/libGLESv1_CM_adreno.so
2019-09-26 14:35:33.094 25133-25188/com.example.hikersapp D/vndksupport: Loading /vendor/lib64/egl/libGLESv2_adreno.so from current namespace instead of sphal namespace.
2019-09-26 14:35:33.095 25133-25188/com.example.hikersapp D/libEGL: loaded /vendor/lib64/egl/libGLESv2_adreno.so
2019-09-26 14:35:33.123 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
2019-09-26 14:35:33.124 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
2019-09-26 14:35:33.124 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
2019-09-26 14:35:33.124 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
2019-09-26 14:35:33.124 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)
2019-09-26 14:35:33.124 25133-25152/com.example.hikersapp W/ample.hikersap: Receiving file descriptor from ADB failed (socket 52): Success
2019-09-26 14:35:33.124 25133-25152/com.example.hikersapp E/ample.hikersap: Something went wrong getting fds from adb. Retry!: Success
2019-09-26 14:35:33.127 25133-25152/com.example.hikersapp W/ample.hikersap: Receiving file descriptor from ADB failed (socket 52): Connection reset by peer
2019-09-26 14:35:33.127 25133-25152/com.example.hikersapp E/ample.hikersap: Something went wrong getting fds from adb. Retry!: Connection reset by peer
2019-09-26 14:35:33.145 25133-25133/com.example.hikersapp I/DecorView: createDecorCaptionView >> DecorView@95b036d[], isFloating: false, isApplication: true, hasWindowDecorCaption: false, hasWindowControllerCallback: true
2019-09-26 14:35:33.172 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection)
2019-09-26 14:35:33.173 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)
2019-09-26 14:35:33.457 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/FontFamily;-><init>()V (light greylist, reflection)
2019-09-26 14:35:33.457 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromAssetManager(Landroid/content/res/AssetManager;Ljava/lang/String;IZIII[Landroid/graphics/fonts/FontVariationAxis;)Z (light greylist, reflection)
2019-09-26 14:35:33.457 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/FontFamily;->addFontFromBuffer(Ljava/nio/ByteBuffer;I[Landroid/graphics/fonts/FontVariationAxis;II)Z (light greylist, reflection)
2019-09-26 14:35:33.457 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/FontFamily;->freeze()Z (light greylist, reflection)
2019-09-26 14:35:33.457 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/FontFamily;->abortCreation()V (light greylist, reflection)
2019-09-26 14:35:33.457 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/graphics/Typeface;->createFromFamiliesWithDefault([Landroid/graphics/FontFamily;Ljava/lang/String;II)Landroid/graphics/Typeface; (light greylist, reflection)
2019-09-26 14:35:33.467 25133-25133/com.example.hikersapp W/ample.hikersap: Accessing hidden method Landroid/widget/TextView;->getTextDirectionHeuristic()Landroid/text/TextDirectionHeuristic; (light greylist, linking)
2019-09-26 14:35:33.540 25133-25133/com.example.hikersapp D/OpenGLRenderer: Skia GL Pipeline
2019-09-26 14:35:33.564 25133-25133/com.example.hikersapp D/EmergencyMode: [EmergencyManager] android createPackageContext successful
2019-09-26 14:35:33.588 25133-25133/com.example.hikersapp D/InputTransport: Input channel constructed: fd=64
2019-09-26 14:35:33.589 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: setView = DecorView@95b036d[MainActivity] TM=true MM=false
2019-09-26 14:35:33.603 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: dispatchAttachedToWindow
2019-09-26 14:35:33.633 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x7 surface={valid=true 533479452672} changed=true
2019-09-26 14:35:33.634 25133-25256/com.example.hikersapp I/Adreno: QUALCOMM build                   : 1c7d42c, If23bcb88b5
    Build Date                       : 01/28/19
    OpenGL ES Shader Compiler Version: EV031.25.03.01
    Local Branch                     : 
    Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.7.4.R1.09.00.00.453.036
    Remote Branch                    : NONE
    Reconstruct Branch               : NOTHING
2019-09-26 14:35:33.634 25133-25256/com.example.hikersapp I/Adreno: Build Config                     : S L 6.0.7 AArch64
2019-09-26 14:35:33.634 25133-25256/com.example.hikersapp D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8998.so from current namespace instead of sphal namespace.
2019-09-26 14:35:33.637 25133-25256/com.example.hikersapp I/Adreno: PFP: 0x005ff112, ME: 0x005ff066
2019-09-26 14:35:33.644 25133-25256/com.example.hikersapp I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
2019-09-26 14:35:33.644 25133-25256/com.example.hikersapp I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
2019-09-26 14:35:33.645 25133-25256/com.example.hikersapp I/OpenGLRenderer: Initialized EGL, version 1.4
2019-09-26 14:35:33.645 25133-25256/com.example.hikersapp D/OpenGLRenderer: Swap behavior 2
2019-09-26 14:35:33.652 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
2019-09-26 14:35:33.653 25133-25256/com.example.hikersapp D/OpenGLRenderer: eglCreateWindowSurface = 0x7c1fb31880, 0x7c35da7010
2019-09-26 14:35:33.653 25133-25133/com.example.hikersapp D/InputMethodManager: prepareNavigationBarInfo() DecorView@95b036d[MainActivity]
2019-09-26 14:35:33.653 25133-25133/com.example.hikersapp D/InputMethodManager: getNavigationBarColor() -855310
2019-09-26 14:35:33.655 25133-25133/com.example.hikersapp D/InputMethodManager: prepareNavigationBarInfo() DecorView@95b036d[MainActivity]
2019-09-26 14:35:33.655 25133-25133/com.example.hikersapp D/InputMethodManager: getNavigationBarColor() -855310
2019-09-26 14:35:33.655 25133-25133/com.example.hikersapp V/InputMethodManager: Starting input: tba=com.example.hikersapp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
2019-09-26 14:35:33.655 25133-25133/com.example.hikersapp D/InputMethodManager: startInputInner - Id : 0
2019-09-26 14:35:33.655 25133-25133/com.example.hikersapp I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2019-09-26 14:35:33.661 25133-25160/com.example.hikersapp D/InputTransport: Input channel constructed: fd=69
2019-09-26 14:35:33.662 25133-25133/com.example.hikersapp D/InputMethodManager: prepareNavigationBarInfo() DecorView@95b036d[MainActivity]
2019-09-26 14:35:33.662 25133-25133/com.example.hikersapp D/InputMethodManager: getNavigationBarColor() -855310
2019-09-26 14:35:33.662 25133-25133/com.example.hikersapp V/InputMethodManager: Starting input: tba=com.example.hikersapp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
2019-09-26 14:35:33.663 25133-25133/com.example.hikersapp D/InputMethodManager: startInputInner - Id : 0
2019-09-26 14:35:33.682 25133-25256/com.example.hikersapp D/vndksupport: Loading /vendor/lib64/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.
2019-09-26 14:35:33.683 25133-25256/com.example.hikersapp D/vndksupport: Loading /vendor/lib64/hw/gralloc.msm8998.so from current namespace instead of sphal namespace.
2019-09-26 14:35:33.945 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: MSG_RESIZED_REPORT: frame=Rect(0, 0 - 1080, 2220) ci=Rect(0, 72 - 0, 144) vi=Rect(0, 72 - 0, 144) or=1
2019-09-26 14:35:33.949 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 0 1
2019-09-26 14:35:33.949 25133-25133/com.example.hikersapp D/InputMethodManager: prepareNavigationBarInfo() DecorView@95b036d[MainActivity]
2019-09-26 14:35:33.949 25133-25133/com.example.hikersapp D/InputMethodManager: getNavigationBarColor() -855310
2019-09-26 14:35:34.119 25133-25133/com.example.hikersapp D/InputTransport: Input channel destroyed: fd=69
2019-09-26 14:35:37.023 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: MSG_WINDOW_FOCUS_CHANGED 1 1
2019-09-26 14:35:37.024 25133-25133/com.example.hikersapp D/InputMethodManager: prepareNavigationBarInfo() DecorView@95b036d[MainActivity]
2019-09-26 14:35:37.024 25133-25133/com.example.hikersapp D/InputMethodManager: getNavigationBarColor() -855310
2019-09-26 14:35:37.026 25133-25133/com.example.hikersapp D/InputMethodManager: prepareNavigationBarInfo() DecorView@95b036d[MainActivity]
2019-09-26 14:35:37.026 25133-25133/com.example.hikersapp D/InputMethodManager: getNavigationBarColor() -855310
2019-09-26 14:35:37.026 25133-25133/com.example.hikersapp V/InputMethodManager: Starting input: tba=com.example.hikersapp ic=null mNaviBarColor -855310 mIsGetNaviBarColorSuccess true , NavVisible : true , NavTrans : false
2019-09-26 14:35:37.026 25133-25133/com.example.hikersapp D/InputMethodManager: startInputInner - Id : 0
2019-09-26 14:35:37.026 25133-25133/com.example.hikersapp I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus
2019-09-26 14:35:37.030 25133-25133/com.example.hikersapp D/InputTransport: Input channel constructed: fd=71
2019-09-26 14:35:37.058 25133-25133/com.example.hikersapp D/ViewRootImpl@3276c23[MainActivity]: setWindowStopped(false) old=false
...