Android Location service didn't work in background

前端 未结 2 523
萌比男神i
萌比男神i 2021-01-14 05:15

I am working on a Location-App which should begin to track some statistic data based on longitude and latitude when the user presses a Button. All this stuff wo

2条回答
  •  余生分开走
    2021-01-14 06:04

    Here is application that does something like you want:

    https://github.com/sergstetsuk/CosyDVR/blob/master/src/es/esy/CosyDVR/CosyDVR.java

    Main Activity starts on BackgroundVideoRecorder service.

    Intent intent = new Intent(/*CosyDVR.this*/getApplicationContext(), BackgroundVideoRecorder.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startService(intent);
    bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
    

    look at mConnection onServiceConnected,onServiceDisconnected.

    Here is BackgroundVideoRecorder class:

    https://github.com/sergstetsuk/CosyDVR/blob/master/src/es/esy/CosyDVR/BackgroundVideoRecorder.java

    It implements LocationListener. So has onLocationChanged, onProviderDisabled, onProviderEnabled, onStatusChanged.

提交回复
热议问题