GCM Notification android

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


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
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.androiddeveloper.notifydemo"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.0'
    compile "com.google.android.gms:play-services-gcm:8.4.0"
}


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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.androiddeveloper.notificationdemo">

    <uses-permission android:name="android.permission.INTERNET" />

    <permission
        android:name="com.example.androiddeveloper.notificationdemo.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.androiddeveloper.notificationdemo.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".LoginActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- This is default reciever, If you need your reciever then impliment it using below code -->
        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />

                <category android:name="com.example.gcm" />
            </intent-filter>
        </receiver>

        <!-- Make service by extending GcmListenerService -->
        <service
            android:name=".MyGcmListenerService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>

        <activity android:name=".MainActivity"></activity>
    </application>

</manifest>

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.getInstance(getApplicationContext());
          GCMId = instanceID.getToken("3608079128",GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
                   
      } catch (IOException e) {
           e.printStackTrace();
       }

  Log.d(TAG, "GCM_ID : "+ GCMId);






COMMENTS

Name

Alert Android Chat Expandable Expandable Listview Expandable Listview with Json Facebook GCM JSON Login Notification PDF SDK 4.0
false
ltr
item
Android Knowledge: GCM Notification android
GCM Notification android
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMAEUMrqpfjs5jydk7F7eq8TNp-e__zr5rtcxSw-NrHNnWOba2H9-cAQwVXH7gO5elzKnBM3Rhkf4CB4MG7D20FaQPsPEOpXLLZRzXaqSM3mBP5Vz55v7B9h1SniO9TPx61CQDg31nTQ7v/s1600/ice_screenshot_20160510-095158.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMAEUMrqpfjs5jydk7F7eq8TNp-e__zr5rtcxSw-NrHNnWOba2H9-cAQwVXH7gO5elzKnBM3Rhkf4CB4MG7D20FaQPsPEOpXLLZRzXaqSM3mBP5Vz55v7B9h1SniO9TPx61CQDg31nTQ7v/s72-c/ice_screenshot_20160510-095158.png
Android Knowledge
http://androidknowledgeblog.blogspot.com/2016/05/gcm-notification-android.html
http://androidknowledgeblog.blogspot.com/
http://androidknowledgeblog.blogspot.com/
http://androidknowledgeblog.blogspot.com/2016/05/gcm-notification-android.html
true
2625512956379495182
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy