Google Map Application Crashing in Lollipop androi

2019-01-15 23:46发布

I am implementing Google map API v2 in my android application. The application works fine in all devices but not in lollipop devices. Application is crashing in lollipop. I did search for this problem but didn't get a reasonable solution. If any one knows about this problem please help me.I'll be very thankful

2条回答
叛逆
2楼-- · 2019-01-16 00:03

Try to use Android Studio to generate Google Maps activity.

查看更多
走好不送
3楼-- · 2019-01-16 00:13

May be you are trying to get location via LocationManager class. This way perfectly works on preLollipop device. But in lollipop it doesnot works. Now Again Google has released a new API but they haven't updated the documentation properly. Here has a location get demo code that will provide you to get Location Object after a certain interval using the new/latest Location Service API.

import android.app.Activity;
import android.location.Location;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationServices;

/**
 * Created by skarim on 10/29/15.
 */
public class GetLocationAfterCertainInterval extends Activity implements  GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener ,
        LocationListener {
    GoogleApiClient apiClient=null;
    LocationRequest mLocationRequest=null;
    private int locationInterval,fastedInterval;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Initialize Your View here.
        setLocationLocationRequest();
    }

    @Override
    public void onDestroy() {
        // Your need of location update is done. So you have to stop the apiClient.
        super.onDestroy();
        this.apiClient.disconnect();
    }


    private void setLocationLocationRequest() {

        try {
            apiClient=new GoogleApiClient.Builder(this).addConnectionCallbacks(this).addOnConnectionFailedListener(this).addApi(LocationServices.API).build();

            mLocationRequest = new LocationRequest();
            mLocationRequest.setInterval(29000);
            mLocationRequest.setFastestInterval(5000);
            mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
            apiClient.connect();

        }catch (Exception e){
            Log.d("LS", e.getMessage() == null ? "" : e.getMessage());
        }

    }
    @Override
    public void onConnected(Bundle bundle) {
        // Your API Client is connected. So can request for updates
        LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, mLocationRequest, this);
    }

    @Override
    public void onConnectionSuspended(int i) {

    }

    @Override
    public void onLocationChanged(Location location) {
        // After your desired interval This api will give you the Location Object.

    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {

    }


}

For more details about this API you can see this Developer Link

My related Answer is here

Sorry for bad English.Thanks

查看更多
登录 后发表回答