I am new to android development and was trying to add a push notification server and also a client(APK).
What I had read though web, I need to register a project with console.developers.google, and than get some ID to be allowed to send or receive push notification. But, what I am trying to do is to simulate the complete environment on my local machine and test it. Can this be achieved?
For example, a push service is registered and sending notification on localhost and also my app(WIP) to receive and push messages again to the service - supposing localhost machine is not connected to the internet.
This is not possible due to how push notifications work using Googles servers.
Push notifications are sent to Googles servers and from there distributed to devices. They are then picked up by the OS, and given to any app that will respond to the intent. It is therefore not possible to do this locally.
For more information on this consult the documentation here.
EDIT
Following on from that comment you wrote, which is a really cool way of getting around it, I found that I could send a notification my doing:
adb shell am broadcast -a com.google.android.c2dm.intent.RECEIVE com.myapp
The difference between yours and mine being that I do not use the -c as that sets a category. You can see all the possible options by doing
adb shell
and then typing
am broadcast
Assuming you only have one device plugged in. (Note that you don't subscribe to notifications you have to send that notification to the app. The app is then programmed to respond to any intent with the action com.google.android.c2dm.intent.RECEIVE.
Does that help?
You can simulate a push notification to your Android device using ADB.
sudo apt-get install adb
android:permission="com.google.android.c2dm.permission.SEND" >
adb shell am broadcast -c com.myapp -a com.google.android.c2dm.intent.RECEIVE -e data "SomeData"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With