Today i am going to show you how to send notification in all registered devices using GCM. Prerequisites 1) API-KEY 2) SENDER ID ...
Today i am going to show you how to send notification in all registered devices using GCM.
Prerequisites
1) API-KEY
2) SENDER ID
3) google-service.json Note :- This file is genereted by google
4) Device id
STEP 1 : Required Key process
GOTO THIS LINK and register your app make sure your package name is right. Copy from androidManifest.xml file.
In my case my package name is = com.example.androiddeveloper.notificationdemo
After adding App name and package name and goto the next page.
ENABLE Cloud messing service So you can get the API KEY and SENDER ID.
Now you have a 1) API-KEY 2) SENDER ID 3) google-service.json
You can get (4)Device id later in coding part.
STEP 2 :- CODING PART
Copy google-service.json in your app folder.
Before we start coding part add API KEY and SENDER ID in your string .xml
Note :- And do not changed string name
ADD THIS LINE IN YOUR Module:App
This is for google play service.
My gradle file
Compare your AndroidManifest file with mine
Note :- Do not forget to change your package name with mine
Add this code for get RegID or GCM ID or Device id
Prerequisites
1) API-KEY
2) SENDER ID
3) google-service.json Note :- This file is genereted by google
4) Device id
STEP 1 : Required Key process
GOTO THIS LINK and register your app make sure your package name is right. Copy from androidManifest.xml file.
In my case my package name is = com.example.androiddeveloper.notificationdemo
After adding App name and package name and goto the next page.
ENABLE Cloud messing service So you can get the API KEY and SENDER ID.
Now you have a 1) API-KEY 2) SENDER ID 3) google-service.json
You can get (4)Device id later in coding part.
STEP 2 :- CODING PART
Copy google-service.json in your app folder.
Before we start coding part add API KEY and SENDER ID in your string .xml
Note :- And do not changed string name
ADD THIS LINE IN YOUR Module:App
compile "com.google.android.gms:play-services-gcm:8.4.0"
This is for google play service.
My gradle file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Compare your AndroidManifest file with mine
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
Note :- Do not forget to change your package name with mine
Add this code for get RegID or GCM ID or Device id
1 2 3 4 5 6 7 8 9 | try { InstanceID instanceID = InstanceID. ; GCMId = instanceID. ; } catch (IOException e) { e. ; } Log. ; |