Google Map app working fine in emulator, crashes when installed on phone
<p>I've created a google maps app for some mountain trails; when I run it on emulator, it's working just fine... (it just doesn't show my current position on the map because of the lack of the GPS signal).</p>

<p>But when I install it on a phone (I've tested it on 2 Huawei P8Lite phones) it doesn't work the same: the screen is enlarged, and it doesn't show my location, neither the zoom in/out buttons or the current location button. Also, the button that I've implemented to show the current latitude and longitude in a toast message (if gps is enabled) only shows a null message (it works on emulator)...</p>

<p>This is the .java file :</p>

<pre><code>package com.example.francydarkcool.maps;

public class MapsActivity extends AppCompatActivity implements OnMapReadyCallback {

    private GoogleMap mMap;
    String color;
    Button mapbttn;

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

        SupportMapFragment mapFragment =
                (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

        mapbttn = (Button) findViewById(R.id.setRangeButton);

        mapbttn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                btncoord();
            }
        });
        //  Bundle String color;

        Bundle save = getIntent().getExtras();
        if (save != null) {
            color = save.getString("marker color");
        }

    }


    public void btncoord() {
        Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();


        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        // get the last know location from your location manager.
        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, android.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;
        }
        Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        // now get the lat/lon from the location and do something with it.
        Toast.makeText(getApplicationContext(), "" + location.getLatitude() + '\n' + location.getLongitude(), Toast.LENGTH_LONG).show();
    }


    @Override
    public void onMapReady(GoogleMap map) {
        mMap = map;

        if (color.equals("red")) {
            mMap.clear();
            LatLng acasa = new LatLng(45.281600, 27.966331);
            mMap.addMarker(new MarkerOptions()
                .position(new LatLng(45.281600, 27.966331))
                .title("Acasa"));
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(acasa, 18));
        }
            else
        if (color.equals("yellowBand1")) {
            mMap.clear();
            mMap.addMarker(new MarkerOptions().position(new LatLng(45.4067, 25.47164)));
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(45.4067, 25.47164), 18));
 }
        else
        {
            mMap.clear();
            Toast.makeText(getApplicationContext(),color, Toast.LENGTH_LONG).show();
            LatLng abc = new LatLng(0, 0);
            mMap.addMarker(new MarkerOptions()
                .position(new LatLng(0, 0))
                .title("Marker")
                .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_you)));
            mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(abc, 18));
        }

        mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &amp;&amp; ActivityCompat.checkSelfPermission(this, android.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;
        }
        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.getUiSettings().isCompassEnabled();
    }
}
</code></pre>

<p>And the log:</p>

<pre><code>09-04 11:04:36.593 14217-14217/? E/HAL: load: id=memtrack != hmi-&gt;id=memtrack

                                        [ 09-04 11:04:36.595 14217:14217 I/         ]
                                        power log dlsym ok
09-04 11:04:36.618 14217-14217/? E/HAL: load: id=fm != hmi-&gt;id=fm
09-04 11:04:36.735 3948-4086/? E/DatabaseUtils: Writing exception to parcel
                                                java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=3601, uid=10108 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10108 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
                                                    at android.app.ContextImpl.enforce(ContextImpl.java:1595)
                                                    at android.app.ContextImpl.enforcePermission(ContextImpl.java:1608)
                                                    at android.content.ContextWrapper.enforcePermission(ContextWrapper.java:664)
                                                    at com.huawei.android.launcher.LauncherProvider.checkPermission(LauncherProvider.java:1369)
                                                    at com.huawei.android.launcher.LauncherProvider.call(LauncherProvider.java:1544)
                                                    at android.content.ContentProvider$Transport.call(ContentProvider.java:398)
                                                    at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:283)
                                                    at android.os.Binder.execTransact(Binder.java:453)
09-04 11:04:36.739 3601-4161/? E/LauncherInteractiveUtil: Call launcher evnt fail. lock=false
                                                          java.lang.SecurityException: Permission Denial: reading com.huawei.android.launcher.LauncherProvider from pid=3601, uid=10108 requires com.huawei.android.launcher.permission.WRITE_SETTINGS: uid 10108 does not have com.huawei.android.launcher.permission.WRITE_SETTINGS.
                                                              at android.os.Parcel.readException(Parcel.java:1602)
                                                              at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
                                                              at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
                                                              at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)
                                                              at android.content.ContentProviderClient.call(ContentProviderClient.java:437)
                                                              at com.huawei.keyguard.support.LauncherInteractiveUtil$Caller.run(LauncherInteractiveUtil.java:59)
                                                              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:246)
                                                              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                              at java.lang.Thread.run(Thread.java:833)
09-04 11:04:36.748 4006-4270/? E/HwSystemManager: TrafficNotifyAfterLocked:screen notification will not notify
09-04 11:04:36.753 4006-4192/? E/HwSystemManager: SimCardMethod:/getSimCardInfo: imsi is null
09-04 11:04:36.756 4356-4416/? E/LogCollectService: LogUpload module not exist
09-04 11:04:36.783 4006-4192/? E/HwSystemManager: NormalTrafficAnalysis:alert byte = 0, so return
09-04 11:04:36.838 4006-4192/? E/HwSystemManager: LeisureTrafficSetting:result is empty
09-04 11:05:28.546 3197-4085/? E/HW_DISPLAY_EFFECT: hw_set_colortemperature: strTmp=256,0,0,0,256,0,0,0,256
09-04 11:05:28.576 3197-3520/? E/PowerManagerService-JNI: QEEXO fs_on_resume NULL, not calling FingerSense
09-04 11:05:28.610 3197-3483/? E/WifiStateMachine:  Fail to set up pno, want false now false
09-04 11:05:28.620 3197-3504/? E/HwBastetService: Failed to get bastet service!
09-04 11:05:28.621 3197-3454/? E/Sensors: ProximitySensor: p sensor data (1)
09-04 11:05:28.700 14277-14277/? E/CAMERA3_PostCamera2: Class(com.huawei.hwpostcamera.HwPostCamera) not found.
09-04 11:05:29.140 8931-8931/? E/HwVAssistant_Ziri.ModelService: processSystemStartEvent: Missing critical permissions.
09-04 11:05:29.140 8931-8931/? E/HwVAssistant_Ziri.ModelService: processSystemStartEvent: false 
09-04 11:05:34.391 4006-4006/? E/HwSystemManager: HandleInstalledPackageInfoService:second action: pkgData is null
09-04 11:05:34.393 2473-2473/? E/SELinux: avc:  denied  { find } for service=batteryproperties scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:healthd_service:s0 tclass=service_manager
09-04 11:05:35.946 14330-14330/? E/Finsky: [1] com.google.android.finsky.wear.bo.a(838): onConnectionFailed: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
09-04 11:05:48.063 14448-14472/? E/linker: readlink('/proc/self/fd/28') failed: Permission denied [fd=28]
09-04 11:05:48.063 14448-14472/? E/linker: warning: unable to get realpath for the library "/system/framework/oat/arm64/com.android.location.provider.odex". Will use given name.
09-04 11:05:48.065 14448-14472/? E/linker: readlink('/proc/self/fd/28') failed: Permission denied [fd=28]
09-04 11:05:48.065 14448-14472/? E/linker: warning: unable to get realpath for the library "/system/framework/oat/arm64/com.android.media.remotedisplay.odex". Will use given name.
09-04 11:05:48.069 14448-14472/? E/linker: readlink('/proc/self/fd/28') failed: Permission denied [fd=28]
09-04 11:05:48.069 14448-14472/? E/linker: warning: unable to get realpath for the library "/data/app/com.google.android.gms-2/oat/arm64/base.odex". Will use given name.
09-04 11:05:48.099 14448-14472/? E/linker: readlink('/proc/self/fd/28') failed: Permission denied [fd=28]
09-04 11:05:48.099 14448-14472/? E/linker: warning: unable to get realpath for the library "/data/app/com.google.android.gms-2/lib/arm64/libgmscore.so". Will use given name.
09-04 11:05:48.103 14448-14472/? W/linker: /data/app/com.google.android.gms-2/lib/arm64/libgmscore.so: unused DT entry: type 0x7ffffffd arg 0xbaa
09-04 11:05:48.128 14448-14472/? E/linker: readlink('/proc/self/fd/28') failed: Permission denied [fd=28]
09-04 11:05:48.128 14448-14472/? E/linker: warning: unable to get realpath for the library "/data/app/com.google.android.gms-2/lib/arm64/libconscrypt_gmscore_jni.so". Will use given name.
09-04 11:05:48.128 14448-14472/? W/linker: /data/app/com.google.android.gms-2/lib/arm64/libconscrypt_gmscore_jni.so: unused DT entry: type 0x1d arg 0x80
09-04 11:05:48.128 14448-14472/? W/linker: /data/app/com.google.android.gms-2/lib/arm64/libconscrypt_gmscore_jni.so: unused DT entry: type 0x7ffffffd arg 0x167
09-04 11:05:48.186 14448-14472/? I/ProviderInstaller: Installed default security provider GmsCore_OpenSSL
09-04 11:05:50.245 2498-2498/? E/Thermal-daemon: [charger_ic] temp_new :35  temp_old :36
09-04 11:05:50.246 2498-2498/? E/Thermal-daemon: Report temperature: [charger_ic] temp :35  report_threshold:1
09-04 11:05:50.456 3197-3469/? E/InputReader: QEEXO fs_classify_touch NULL, not calling FingerSense
09-04 11:05:50.469 14546-14546/com.example.francydarkcool.maps I/HwSecImmHelper: mSecurityInputMethodService is null
09-04 11:05:50.496 2474-2474/? E/HAL: load: id=gralloc != hmi-&gt;id=gralloc
09-04 11:05:50.513 2474-2474/? E/HAL: load: id=gralloc != hmi-&gt;id=gralloc
09-04 11:05:50.523 3197-3469/? E/InputReader: QEEXO fs_touch_up NULL, not calling FingerSense
</code></pre>

<p>When I run it on an emulator, I have no errors.</p>