Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating android GCM

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.

like image 229
john0609 Avatar asked Jan 06 '15 14:01

john0609


2 Answers

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?

like image 106
MungoRae Avatar answered Nov 07 '22 06:11

MungoRae


You can simulate a push notification to your Android device using ADB.

  1. Install adb first.

sudo apt-get install adb

  1. Remove the SEND permission from manifest.xml.

android:permission="com.google.android.c2dm.permission.SEND" >

  1. Command to push notifications from shell

adb shell am broadcast -c com.myapp -a com.google.android.c2dm.intent.RECEIVE -e data "SomeData"

  1. Change the package name (com.myapp) and "SomeData" as you want.
like image 1
Parinda Rajapaksha Avatar answered Nov 07 '22 06:11

Parinda Rajapaksha