forked from Freeyourgadget/Gadgetbridge
WIP: [intents-handling] Extend intent functionality #1
Loading…
Reference in a new issue
No description provided.
Delete branch "(deleted):intents-handling"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Now also supports starting activities in addition to sending broadcasts. Targeting services is yet to be implemented.
action, category, mimeType, data, extra, package, class and target information can now be supplied to intents (these are also the corresponding keys to use when programming intent messages to send to gadgetbridge).
Regarding WIP tag:
I think this PR can be merged as it is now, but I'm fine with waiting as well.see comments.Thanks! This looks good - and really useful, but is there a specific reason to iterate over arguments and use a switch rather than just checking for them with
.has(name)
and accessing them directly? It seems different to the way other code in that file works.I guess you can report on extra fields you weren't expecting, but it does seem to have the slighting odd issue that the order of JSON fields matters, so the JSON
{..., package:..., class:...}
works, but{..., class:..., package:...,}
doesn't.Thanks for the feedback!
Maybe not! It's probably just a sign of my inexperience and using trial and error until it worked. I'll see if I can look at other parts of the code and use a similar style.
Would you recommend I don't?
Could you share the messages you sent to test this?
@gfwilliams, I've done some changes trying to take your tips into account. I'm unsure if I should change the switch-case for handling target to if-statements as well? I feel like it makes sense to keep that as is though?
Just noticed that starting the activity ( startActivity() ) to open and play a song on spotify isn't as reliable as sending a broadcast to Tasker and letting tasker send the same intent to start the activity instead.
Without Tasker it works when certain apps are displayed, e.g. Gadgetbridge and android settings app. But not when e.g. my launcher app or Signal messaging app is displayed. With Tasker it works independent of what app is currently in the foreground.
I'm guessing it has something to do with setting the right context when calling startActivity(). But I don't understand how to set a context which lets me activate the activity from anywhere.
Hi - yeah, I'm afraid I don't know much about startActivity so I can't really help you there - have you checked to see if it's used anywhere else in Gadgetbridge? It might give you some hints.
Those changes look great to me. Personally I'd probably make the text for
target
all lowercase without spaces, just to match what we send for other fields a bit better (http://www.espruino.com/Gadgetbridge#messages-sent-to-bangle-js-from-phone) but unless you have any reasons not to I'd be very happy to merge this in now?I'll do that!
I'll check that out as well!
Now when I've seen that starting activities is a little hit and miss, I would like to see if I can fix that before it's merged.
Thanks for the tips! :)
Ok, great - thanks! This is going to be a really neat addition when it's merged in
I got this question in the Gadgetbridge matrix chat:
What do you say @gfwilliams, should the PR be switched over to the main Gadgetbridge project?
Yes, that sounds great to me. Saves me having to push it back :)
This Tasker forum post had the answer to how to let Gadgetbridge start activities while in the background. It needs the permission SYSTEM_ALERT_WINDOW which is now introduced to the bangle.js AndroidManifest.xml file. The user needs to grant this permission in system settings app info section. Ideally I would want there to be a pop-up like with other permissions (e.g. location, notifications, do not disturb) which forwarded the user to this section for easier access. I don't know how to do this though, yet at least.
I have changed it to what I think you suggested. But from looking at the espruino gadgetbridge documentation in the link I don't really see a precedent for the values of the dictionary/JSON always being lower case without spaces - only the keys. Is the change in line with what you thought of?
Ok, I'll do a PR to the main project and close this one after you've answered my question regarding keys and values above. :)
This looks really good to me - thanks!
You could take a look at app/src/main/java/nodomain/freeyourgadget/gadgetbridge/activities/ControlCenterv2.java - that's where we request permissions for the other stuff. You can see where we check for INTERNET_ACCESS (based on the current build)
Maybe something like this might do it (untested!):
Well, I think they are all upper or lower, and without spaces?
But yes, ideally they should all be lowercase but that's not always the case.
Yes, that's perfect - thanks :)
Yes, I get it now when I look again. I was confused by e.g. "src":"Hangouts".
I'll give the permission pop-up a try. :)
I've implemented the pop-up for allowing displaying over other apps.
I'll close this PR now and open a new one to the main Gadgetbridge project.
Thanks for all the feedback! :)
@ -581,0 +600,4 @@
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
startActivity(new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
Uri.fromParts("package", "com.espruino.gadgetbridge.banglejs", null)));
Just thinking here we might want to use BuildConfig.APPLICATION_ID instead, so it can work with other builds.
...and, does this definitely not come up for 'normal' Gadgetbridge builds where SYSTEM_ALERT_WINDOW isn't in the manifest?
@ -581,0 +594,4 @@
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
Context context = getContext();
builder.setMessage(context.getString(R.string.permission_display_over_other_apps,
Just checking, but is permission_display_over_other_apps defined? I don't see it in strings.xml
This is probably an oversight on my part b/c of my inexperience. Trial and error is yet again how I got to that code. I will try to implement what you suggest! :)
I don't know, really... If you think so I would believe that is the case. Hmm, do you have a suggestion on what I should to to do it right?
Yeah, I believe so. The pop-up message looks as I want it at least. I'll check though. EDIT: I only had it locally. I have uploaded now. But since I had closed the PR now the code wont sync here.
Thanks! And sorry for suggesting all the changes :) What you've done looks great, but it's just making it so it doesn't break anything for 'normal' Gadgetbridge users.
As far as I can tell, ACTION_APPLICATION_DETAILS_SETTINGS is bringing up the settings page for the particular app so permissions can be enabled? This is a great idea as Gadgetbridge never seemed to be able to do that before. I always found giving permissions for Background Location was a real pain.
But looking at it, I see you check
if (!set.contains(this.getPackageName())) {
which what the Notification Listener does in the few lines above - so I think it's only checking for notification permissions? It feels like it might actually want to be checking something else?Maybe:
But maybe it's useful for other things too (like the background location)...
For
permission_display_over_other_apps
It could be changes tostrings.xml
didn't get committed? I don't see it in the app here and it doesn't seem to be in the PR?Yes, I tried to mimic how permissions for notifications and do not disturb was implemented and used stackoverflow.
Yes, I started with copying that code :P
Ok, that makes sense!
Yes, exactly what happened ;) And I can't sync the fork to this PR anymore.
I've tried that now and it's perfect! ;)
I'll get to opening the other PR now so you can follow along in the code again.
Is this still an issue after I implemented your latest suggestion do you think?
No, that's fine - the
BuildConfig.FLAVOR.equals("banglejs")
should fix that :)Thanks for doing all these tweaks - it'll be great to get this into builds!
Perfect! Thanks for helping me as well! :)
The PR to the main project is here.
Pull request closed