How to use generated API key in GCM code android - android

I want to integrate GCM in android application for which I have registered my application and enabled GCM service on google developer console also created the API key.
Where to put this API key in android code ?
Any help appreciated.

You don't have to use api key in android code.
You have to use this api key at server side to send notifications and use project number in android code to register device for GCM and obtain unique device id for receiving notifications.
STEPS TO USE GCM
Register the Android app with GCM to receive Registration Id “RegId“
Share “RegId” with the server
Send a message from server to GCM using HTTP POST request
You can read step by step implementation of GCM here.

Related

Is there any work around to use Fcm device id with Gcm backend?

The problem is we have GCM integrated at the backend and when I try to add a new app to console it takes me to Firebase console when I click on google could messaging and when I send firebase device id to backend it is using GCM library to send notifications and gives mismatch sender id error. I know we have to implement FCM at the backend but is there any work around for sending notifications using GCM while using FCM device id from the backend?

Is client id or server id needed in android code for gcm notification?

I want to know "if client id or server id is needed in android code for gcm notification?"
Yes you need server id(i.e API Key). you get this server id from google developer console by creating project. Follow these steps to create project on google developer console
and you also need client id to send notifications to the clients who subscribed to Push notifications

My Gcmdemo project not working

I have used gcm demo code for viewing working of different features of gcm.But unfortunately it is showing some error.My client side is gcm quickstart code ,which is working finely,successfully sent notification using command code(gcm sender) .But i have few doubts-
Is it possible to send message/notification from gcm demo code to gcm quickstart?
2.I have used sender id and api key of gcm quickstart for sending notification from gcm demo.
3.Is there any correction required in gcm demo?
As GCM Reference 401 is authentication issue and possible problems are explained below;
The sender account used to send a message couldn't be authenticated.
Possible causes are:
Authorization header missing or with invalid syntax in HTTP request.
Invalid project number sent as key.
Key valid but with GCM service disabled.
Request originated from a server not whitelisted in the Server Key IPs.
Check that the token you're sending inside the Authentication header
is the correct API key associated with your project. See Checking the
validity of an API Key for details.

API key for GCM

When using the API key generated for my project from Google developer console in the server side to send GCM - Push notifications, i am getting a 'MismatchSenderId' error. I have cross checked the sender ID in my application and the API key also, which is correct.
Also when creating an API key for push notification implementation, should i go for 'Server key' or 'Browser key' or 'Android key' .I have maps implementation also in my project.
I am new to push notification implementation, so kindly excuse if question is too broad.
when creating an API key for push notification implementation, use:
Server Key to send from your server
Browser Key to send from a web app
Android Key to send from an android app.
also the Sender Id, is really the project id.

to use GCM, each device will need to register?

I am very confused to use GCM service, I have sender id, api key and registered emulator so got registration id.
Now, next what to do ?
I want that whever new version is available, user get notification or alert dialog which will show new version is available. Then 2 buttons, update now and update later.
I am using ASP.NET server.
By using gcm sender id,you will use in android ie client side and server browser api in server side say php side. So when a device opens,it will create gcm register id at server side and intermediate is gcm account and it will monitor the device.so you can send notification from server to client. For same device,only unique gcm registration id will be generated.
See this tutorial
http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

Categories

Resources