Hola, tengo un drama, no puedo hacer que funcione el gps en la API-23, arroja problema a la hora de los permisos los coloque == para evitar drama, exsten recomendaciones de inicializar el GPSTRACKING en el OnCreate que tambien incorpore pero nada me funciona y solo es error para la 23 o posterior
este es el logCat
07-01 16:07:51.501 1055-1055/app.supega.supegatrab E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.myapp, PID: 1055
java.lang.RuntimeException: Unable to create service info.androidhive.supegatrab.activity.MyAlarmService: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3818)
at android.app.ActivityThread.access$2100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1883)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.content.Context.checkPermission(java.lang.String, int, int)' on a null object reference
at android.content.ContextWrapper.checkPermission(ContextWrapper.java:665)
at android.support.v4.content.ContextCompat.checkSelfPermission(ContextCompat.java:387)
at info.androidhive.supegatrab.util.GPSTracker2.getLocation(GPSTracker2.java:66)
at info.androidhive.supegatrab.util.GPSTracker2.<init>(GPSTracker2.java:47)
at info.androidhive.supegatrab.activity.MyAlarmService.onCreate(MyAlarmService.java:50)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3808)
at android.app.ActivityThread.access$2100(ActivityThread.java:222)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1883)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:7229)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Y ESTE, la parte del codigo donde arroja el error
if (location == null) {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
Nota:
Esto es de una clase que extiende de:
LocationListener
y Esta clase es llamada desde una clase:
Service
PDA: no me dejo cargar con modo codigo