Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drive the app via Intents using BroadcastReceiver #194

Open
GrazianoCapelli opened this issue Nov 21, 2022 · 2 comments
Open

Drive the app via Intents using BroadcastReceiver #194

GrazianoCapelli opened this issue Nov 21, 2022 · 2 comments
Labels
enhancement This is an enhancement of an existing feature

Comments

@GrazianoCapelli
Copy link
Member

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.

@GrazianoCapelli GrazianoCapelli added the enhancement This is an enhancement of an existing feature label Nov 21, 2022
@Offerel
Copy link

Offerel commented May 26, 2024

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

@GrazianoCapelli
Copy link
Member Author

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is an enhancement of an existing feature
Projects
None yet
Development

No branches or pull requests

2 participants