Drive the app via Intents using BroadcastReceiver
GrazianoCapelli opened this issue · comments
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:
The implementation of this feature is possible only if the permission to access the background location is granted.
Is this feature available in the current stable release? I have tried to send the intent visible in the screenshot, but nothing happens.