Android Open Source - android-messaging-push-tutorial Gcm Intent Service






From Project

Back to project page android-messaging-push-tutorial.

License

The source code is released under:

MIT License

If you think the Android project android-messaging-push-tutorial listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.sinch.messagingtutorial.app;
//  w w  w.j a v a 2  s  .c  o m
import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

public class GcmIntentService extends IntentService {
    public static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;

    public GcmIntentService() {
        super("GcmIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {

        mNotificationManager = (NotificationManager)
            this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, LoginActivity.class), 0);

        NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("New Message!");

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());

        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
}




Java Source Code List

com.sinch.messagingtutorial.app.GcmBroadcastReceiver.java
com.sinch.messagingtutorial.app.GcmIntentService.java
com.sinch.messagingtutorial.app.ListUsersActivity.java
com.sinch.messagingtutorial.app.LoginActivity.java
com.sinch.messagingtutorial.app.MessageAdapter.java
com.sinch.messagingtutorial.app.MessageService.java
com.sinch.messagingtutorial.app.MessagingActivity.java
com.sinch.messagingtutorial.app.MyApplication.java