BasicAirData / GPSLogger

A GPS logger for Android mobile devices
http://www.basicairdata.eu/projects/android/android-gps-logger/
GNU General Public License v3.0
392 stars 121 forks source link

Drive the app via Intents using BroadcastReceiver #194

Open GrazianoCapelli opened 1 year ago

GrazianoCapelli commented 1 year ago

Currently the app is driveable with Hotkeys (#168), we could add also the possibility to drive it with Intent. We could define custom actions and listen for them with the ActionsBroadcastReceiver.

Define a custom action is easy. For example, to start recording:

Add the action filter to AndroidManifest.xml:

<receiver android:name=".ActionsBroadcastReceiver"
    android:exported="false">
    <intent-filter>
        <action android:name="android.intent.action.ACTION_SHUTDOWN" />
        <action android:name="eu.basicairdata.graziano.gpslogger.ACTION_START_RECORDING" /><-- ADDED THIS LINE /-->
    </intent-filter>
</receiver>

Add the case management to ActionBroadcastReceiver.java:

case "eu.basicairdata.graziano.gpslogger.ACTION_START_RECORDING":
    // Start Recording
    // Code copied from GPSActivity.onKeyUp
    if (!GPSApplication.getInstance().isStopButtonFlag() && !GPSApplication.getInstance().isRecording())
        GPSApplication.getInstance().setRecording(true);
    break;

Add the action and register into the receiver in GPSApplication.java onCreate:

...
IntentFilter filter = new IntentFilter(Intent.ACTION_SHUTDOWN);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_SCREEN_ON);
filter.addAction("eu.basicairdata.graziano.gpslogger.ACTION_START_RECORDING");        // Register the action
registerReceiver(broadcastReceiver, filter);
...

This way the app can be driven via intents, also in background, with task automation apps. The code here above has been successfully tested with MacroDroid:

photo_2022-11-21_23-01-42

The implementation of this feature is possible only if the permission to access the background location is granted.

Offerel commented 4 months ago

Is this feature available in the current stable release? I have tried to send the intent visible in the screenshot, but nothing happens.

GrazianoCapelli commented 10 hours ago

No, at this time the feature has not been implemented because it would require the background location permission.

PS: I noticed just now that I didn't answered your question, thus sorry for the late answer!