Android Question LiveEventBus

Is there a library or another way to receive events from an Android Studio app which uses this code to send events?
Send event:
 LiveEventBus
                        .get("myKey")
                        .postAcrossApp(new NoticeEvent(simp));
Receive event:
LiveEventBus
                .get("myKey", NoticeEvent.class)
                .observe(this, new Observer<NoticeEvent>() {
                    @Override
                    public void onChanged(@Nullable NoticeEvent event) {
                        if (event != null) {
                            if (event.getNotice() == 0x01...

I think that this is JeremyLiao/LiveEventBus from github
 
I've managed to add greenrobot's eventbus to and android studio app that register and post messageevent, but I can't receive from my B4A app with eventbus library, the event do not fire. I've tested with two different android studio apps and event do not fire. It only fire to suscriptors in the same app. Is it normal?
¿What is the problem?
 
Upvote 0
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I've managed to add greenrobot's eventbus to and android studio app that register and post messageevent, but I can't receive from my B4A app with eventbus library, the event do not fire. I've tested with two different android studio apps and event do not fire. It only fire to suscriptors in the same app. Is it normal?
¿What is the problem?
not clear (to me) exactly what you're saying.
when you say "greenbot's eventbus", are you referring to my library?
i've already said (in your other post) that you would probably not be able to use 2 different libraries to commuicate.
if you build 2 small probject with my library, you should see that you can pass objects back and forth.
the "problem" (as i understand it) is compatibility between the 2 libraries. if you're saying that my library doesn't work when you use it with 2 b4a apps that you build, then that is an actual problem.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
Are you saying that I can receive messages from liveEventBus in my B4A app with broadcast intents? Can you give me more details?

May be this? https://www.b4x.com/android/forum/threads/broadcast-receiver-not-working.95679/#content
if that library uses intents, then they will have an action and carry some data (aka, "extras"). if you know what the action is (there aren't all that many, unless a custom intent is being used) and how the "extras" are referred to, any app can receive data from liveeventbus. if you have the library's source, you can find out what you need to know. you have to find the class or module that uses the intent. note: there may be a problem using broadcast receivers between apps on recent android versions. i'm pretty sure i saw something about that (i was looking into that topic myself).
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
have you tried to send a message from the android studio app?
what happens?

the library's intent contains no action. its "extra" is "result_extra_key".
according to android's dox, if an intent has no action, an intent filter need
only list any action in order to qualify to receive the intent. in other words,
the intent does not need an action, but an intent filter does. any action will do.

i have to assume that you have apps on your device which can be launched
by receiving an intent. this means that when the android studio app broadcasts
a message, android should show a list of apps which can receive an intent.
is this what happens? if not, then there is more to the library than simply
communicating via intents. i notice there seems to be some sort of "key" needed.

if the system shows a list of apps (as described) above, then you can create a
small b4a app to get on that list and receive the message. there is no sense
in getting into that if the message from the android studio app does not cause
android to show a list of apps that can handle the intent.

frankly, i don't understand why you even need liveeventbus. if you know what
android studio app is observing (listening for), you can do it yourself. there is
an observable library here.
 
Upvote 0
have you tried to send a message from the android studio app?
what happens?

the library's intent contains no action. its "extra" is "result_extra_key".
according to android's dox, if an intent has no action, an intent filter need
only list any action in order to qualify to receive the intent. in other words,
the intent does not need an action, but an intent filter does. any action will do.

i have to assume that you have apps on your device which can be launched
by receiving an intent. this means that when the android studio app broadcasts
a message, android should show a list of apps which can receive an intent.
is this what happens? if not, then there is more to the library than simply
communicating via intents. i notice there seems to be some sort of "key" needed.

if the system shows a list of apps (as described) above, then you can create a
small b4a app to get on that list and receive the message. there is no sense
in getting into that if the message from the android studio app does not cause
android to show a list of apps that can handle the intent.

frankly, i don't understand why you even need liveeventbus. if you know what
android studio app is observing (listening for), you can do it yourself. there is
an observable library here.
The problem was that I have to receive messages from an app made by other company. So, It would be wonderful if I can receive and send messages directly to that app that uses LiveEventBus from my B4A app. The app do not cause android to show a list o apps that can handle the intent. I've asked the other company to change the communication method to standard broadcast messages, with a defined action and extra data, to avoid problems from B4A.
 
Upvote 0
From a quick look in the source code, it broadcasts intents. There is nothing special about it, but you do need to know the expected intent filter signature and add it with the manifest editor.
I've added a receiver module to my app and I receive broadcast messages perfect, unless I put API > 25. Why?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
I've added a receiver module to my app and I receive broadcast messages perfect (...)

you receive broadcasts from the android studio app? or you receive broadcasts from an example posted on the forum?

what does your manifest look like? what does the receiver look like?
 
Upvote 0
you receive broadcasts from the android studio app? or you receive broadcasts from an example posted on the forum?

what does your manifest look like? what does the receiver look like?
I receive broadcast from the android studio app to my B4A with targetSdkVersion="25", but do not receive when I change to "33".
This is my manifest.xml:

B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddPermission(android.permission.RECEIVE_ULTRASONIC_API)
AddReceiverText(myReceiver,
<intent-filter>
    <action android:name="com.seinco.broadcastreceiver.CUSTOM_INTENT" />
</intent-filter>)

And this is myReceiver.bas added as receiver type to the B4A app that works fine with targetSdkVersion="25":
B4X:
Sub Process_Globals
    
End Sub

'Called when an intent is received.
'Do not assume that anything else, including the starter service, has run before this method.
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)   
    Log(StartingIntent)
End Sub
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
to receive a non-system broadcast, you need to add:
SetReceiverAttribute(myReceiver, "android:exported", true)
to your manifest. try that
 
Upvote 0
Top