Broadcasting intents when a file is selected

Support for Android version of Total Commander

Moderators: white, Hacker, petermad, Stefan2

Post Reply
ienne
Junior Member
Junior Member
Posts: 17
Joined: 2017-06-26, 15:49 UTC

Broadcasting intents when a file is selected

Post by *ienne »

Hello.

I understand very little of Android activities and intents. There is something I would like to do from TC but I cannot quite understand whether it is possible.

After selecting an MP3 file or an M3U8 playlist, I would like to have a button to broadcast the intent "gonemad.gmmp.command.ENQUEUE_FILE" with the string extra "filename" set to "%P%N".

Is it possible?

I can add a button "View file with app" and invoke GoneMAD's main activity, which plays the file or the playlist. This is almost what I wish, except that this replaces the current queue instead of appending to the queue. Apparently, I can only achieve the latter by broadcasting an intent instead.

Best,

p.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Broadcasting intents when a file is selected

Post by *ghisler(Author) »

Yes, you can do this with a button in the lower toolbar. First, set the type to view file, and then pick the app GoneMAD.
Then you need to put two lines in the parameters field:
action:gonemad.gmmp.command.ENQUEUE_FILE
extra0:filename:%P%N

This may not work when the GoneMAD app needs a content URL instead of a name. Then use this:
action:gonemad.gmmp.command.ENQUEUE_FILE
extra0:filename:%C

I would copy and paste this so you don't have to type it all.
Author of Total Commander
https://www.ghisler.com
ienne
Junior Member
Junior Member
Posts: 17
Joined: 2017-06-26, 15:49 UTC

Re: Broadcasting intents when a file is selected

Post by *ienne »

Thanks, Christian, looks fantastic!

Only... I did not manage to get it to work, though. Besides trying both versions you suggested, I have also attempted something simpler from this list to factor out the string extra format, just in case. I simply used

Code: Select all

action:gonemad.gmmp.command.PAUSE
and would have expected that GoneMAD simply pauses if currently playing. What happens (both with this simpler intent as well as with the two versions of your response) is that GoneMAD opens up without any change to the playing status or the queue.

Here is a screenshot of the definition of the "simpler" button, in case I misunderstood something in the instructions:

Image: https://drive.google.com/file/d/1obndHMBjtMGxnjRIw05dL_wEMtWBSo0M/view

What have I done wrong?

p.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Broadcasting intents when a file is selected

Post by *ghisler(Author) »

The pause event is not handled by the main activity but by some specialized activity.
In the command field, please replace
.ui.main.MainActivity
with
.receivers.BackupReceiver
Note the dot at the start.
Author of Total Commander
https://www.ghisler.com
ienne
Junior Member
Junior Member
Posts: 17
Joined: 2017-06-26, 15:49 UTC

Re: Broadcasting intents when a file is selected

Post by *ienne »

I would love to have a clue how to fix these things myself, but I have no clue and... alas, it does not work.

Here is the current version:

Image: https://drive.google.com/file/d/1RqoZwzE5rzW7jggSjmemXi-XngdKKODq/view

The complete command is now "GoneMAD:gonemad.gmmp:.receivers.BackupReceiver".

When I press the button, I get "Unable to find explicit activity class {gonemad.gmmp/gonemad.gmmp.receiv..."

I wish I could debug this myself--any hints to relevant documentation are most welcome.... :-(

p.
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Broadcasting intents when a file is selected

Post by *ghisler(Author) »

This should work according to their documentation. What you can also try is leaving empty the command field entirely, then the action will be sent to all apps which can handle it (via app picker if there are more than one).
Author of Total Commander
https://www.ghisler.com
ienne
Junior Member
Junior Member
Posts: 17
Joined: 2017-06-26, 15:49 UTC

Re: Broadcasting intents when a file is selected

Post by *ienne »

Firstly, my apologies. I finally saw where you got the ".receivers.BackupReceiver" and I also realized that I never pressed the ? in the Button Properties window of TC: there is quite a bit of documentation that I completely missed.

This said, I tried to omit completely the command and I get "No Activity found to handle Intent", which seems to suggest that the intent names are incorrect.... I updated a post on the GMMP forum for help....
ienne
Junior Member
Junior Member
Posts: 17
Joined: 2017-06-26, 15:49 UTC

Re: Broadcasting intents when a file is selected

Post by *ienne »

This is the post on the GMMP forum: https://gonemadmusicplayer.proboards.com/thread/1396/enqueueing-playlist-track-another-app. It is not clear to me what is wrong (except that .receivers.BackupReceiver was probably incorrect).
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48021
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: Broadcasting intents when a file is selected

Post by *ghisler(Author) »

Thanks for the link. It looks like you have to use am broadcast instead of am start. The equivalent code would be
sendBroadcast(intent);
but Total Commander can only use
startActivity(intent);

Therefore it's currently not possible to communicate with GMMP.
I will add it to the next beta.
Author of Total Commander
https://www.ghisler.com
ienne
Junior Member
Junior Member
Posts: 17
Joined: 2017-06-26, 15:49 UTC

Re: Broadcasting intents when a file is selected

Post by *ienne »

Thanks!
Post Reply