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
Asked
Active
Viewed 2,367 times
-2
-
Add your logcat here..!! – AndiGeeky Oct 21 '15 at 05:14
-
please show your log – Hari Krishnan Oct 21 '15 at 05:15
-
Sorry i didn't have a device with 5.0 to debug the code. i am testing it on 4.4.4 and its working fine. But my client has 5.0 and when he tests the app then app crashes – Mehtab Ahmed Oct 21 '15 at 05:45
2 Answers
1
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

Community
- 1
- 1

Md. Sajedul Karim
- 6,749
- 3
- 61
- 87