Which component of Android does receive the google cloud messaging message - android

Google says: "GCM delivers messages as a broadcast. The receivers must be registered in the manifest in order to wake up the application." but What component of Android does actually get the message first? Because İ dont think the Client app is the first component that gets the message by Broadcast receiver.
Would be happy if someone can explain it A bit more or give me A link to a source. Thx

The client app is really the first component to get this broadcast by a broadcast receiver. Not only that, it is the only component to get it, simply because nobody else can listen for that specific broadcast (the one that is defined in your application's manifest).
But I guess you wanted to know who gets the message from the network and sends this broadcast. That is Google Play Services.

Related

android13 RECEIVER_EXPORTED's explanation is correct?

Choose whether the broadcast receiver should be exported and visible
to other apps on the device. If this receiver is listening for
broadcasts sent from the system or from other apps—even other apps
that you own—use the RECEIVER_EXPORTED flag. If instead this receiver
is listening only for broadcasts sent by your app, use the
RECEIVER_NOT_EXPORTED flag.
this is that google explains RECEIVER_EXPORTED, RECEIVER_NOT_EXPORTED
link to explanation
when i want to use broadcasts sent from the system
google say i need to use RECEIVER_EXPORTED
but when i tested with "android.intent.action.AIRPLANE_MODE" and "RECEIVER_NOT_EXPORTED"
I received boradcast event.
can anyone explain that sentence?
There might be an error in their document or they changed their mind, because according to ContextCompat documentation, you can use:
RECEIVER_NOT_EXPORTED if you only want your receiver to be able to receive broadcasts from the system or your own app.
In my opinion, it's safer like this, because we don't want our receiver to be open to all applications just to get system broadcasts.
(edited) I found also this on the RECEIVER_NOT_EXPORTED documentation:
Has the same behavior as marking a statically registered receiver with "exported=false"
And when I look at receiver documentation, for the exported attribute, I read:
If "false", the only messages the broadcast receiver can receive are those sent by the system, components of the same application, or applications with the same user ID
So I'm confident enough that the implementation is coherent and there is a small error in the documentation

send broadcast restricted to dynamic list of applications

my application defines events that other apps installed on the device could be registered to (like other apps can register to google play services location updates and activity recognition events).
google play services process notify this types of events via PendingIntent provided by the receiving app.
I prefer to do it by sending a broadcast restricted by permissions, and I think that from a good reason: PendingIntent cannot be saved in persistent way, so every time my app will shout down, the apps that that registered to my events will have to re-register to my events..
the problem: in the link I provided, you can see how to restrict broadcast by custom permission declared in both sides (the broadcast sender application, and the receiving application), but what if I need to decide from the senders side dynamically from a list I'm getting from the server, what are the apps that allowed to receive the broadcast?
I don't find any reference or example in the web how to do so.
I guess it suppose to be possible somehow, because seems like google play services is using this approach for notifying GCM push notifications only to the relevant receiver...
please help me understand how can I do such a thing.
but what if I need to decide from the senders side dynamically from a list I'm getting from the server, what are the apps that allowed to receive the broadcast? I don't find any reference or example in the web how to do so.
Use an explicit Intent, where you have set the ComponentName of the specific BroadcastReceiver that you are "broadcasting" to. You will need to "broadcast" such an explicit Intent once per app that is "allowed to receive the broadcast".

Receiving GCM Android Notifications while App is not Running

I'm confused by the GCM documentation in how to receive a notification on a client device when the app I'm developing is not running. I've tried googling and reading stackoverflow on this topic, but I haven't gotten complete clarification yet.
Do I just extend GCMBaseIntentService to receive notifications, add the service name to my manifest file, and then my service that extended GCMBaseIntentService will automatically handle notifications to my app, even when the app itself is not running? Is there anything else I need to do?
Thanks!
P.S. I found a thread with a similar title, but it doesn't seem to be the same question.
From doc :-
An Android application on an Android device doesn't need to be running
to receive messages. The system will wake up the Android application
via Intent broadcast when the message arrives, as long as the
application is set up with the proper broadcast receiver and
permissions.
Then what is confusion here?

GCM life cycle confusion and wanting to always be registered

I have GCM completely working. My question is when I exit my app with the android BACK key I see the onDestroy() called and to avoid leaks I unregistered the receiver for gcm so it's onUnregister() is called. But I want to be able to register gcm once at power up (boot completed?) and then be able to get notifications any time. I know I will need to still handle when google may refresh the reg intent. But I'm not clear if I need to make a new service to register gcm in in its onCreate()? Right now I register gcm in the main activity's onCreate().
Thanks for any help!!
Justin
Without looking at your code it's a bit hard to tell, but you should not be unregistering from GCM every time you leave the app. A typical GCM App life-cycle (if you are using the GCM jar) would be the following:
App starts and checks to see if it has a GCM registrationID (which means that it registered with GCM) then checks to see if it has registered with your server.
If it has a registrationID but has not registered with your server it attempts to do that.
If it does not have a registrationID it attempts to register with GCM, and then when it gets the registrationID it will attempt to register with your server
Number 4 would probably be unregistered from GCM when they turned off a preference to unregister from receiving notifications.
Take a look at Google's Client sample DemoActivity: http://code.google.com/p/gcm/source/browse/samples/gcm-demo-client/src/com/google/android/gcm/demo/app/DemoActivity.java
Notice that they do not unregistered from GCM. If you follow their sample you will receive notifications after the device powers up without having to do anything else yourself.

Android program - reacts when skype message received?

I am making an android program that needs to do something when I receive a message from the Skype app. My Skype will be logged in, and it will be a service or activity waiting for someone to message me, and when it does it will play a song. Does anyone know how, code-wise, I can tell if I have received a message from the Skype app?
If there is no way to do this, how can I have a service scan the notification bar for a notification that contains the text "skype" and react right when it's received?
Thanks for any help.
If skype broadcasts intent upon message reception ( look into decumentation of skype if there is one ) you may just receive it ( via broadcast receiver ) in your application and do something. Incase it does not, there may be still workauround to snoop into status bar:
Detect a new Android notification
for skype notifications
In general "no". There's no way to do that on non-modified system.
You cant intervene other app's events and/or processing directly. It is only possible if Skype itself has provided an open interface (like Service Binding, Broadcast, etc.) to allow third-party integration. But as per my knowledge, I don't think its possible with Skype's own app.
However, if you use Skype's SDK and offer your own implementation of messenger service, then of course you'll be the in-charge.
According to this post in the Skype Developer Forum, the app does not send broadcast events (which would be the usual way to be programmatically notified of incoming messages).

Categories

Resources