Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
[email protected] webmail now available. Want one? Go here.
Cannot use outlook/hotmail/live here to register as they blocking our mail servers. #microsoftdeez
Obey the Epel!

Paste

Pasted as Java by registered user neetika ( 12 years ago )
package com.live2support;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import android.preference.PreferenceManager;
import android.util.Log;

public class C2DMMessageReceiver extends BroadcastReceiver {
 static boolean active = false;

 @Override
 public void onReceive(Context context, Intent intent) {
  String action = intent.getAction();
  Log.w("C2DM", "Message Receiver called");
  if ("com.google.android.c2dm.intent.RECEIVE".equals(action)) {
   Log.w("C2DM", "Received message");
   final String payload = intent.getStringExtra("message");
   Log.d("C2DM", "dmControl: payload = " + payload);
   // TODO Send this to my application server to get the real data
   // Lets make something visible to show that we received the message
   

   createNotification(context, payload);

  }
 }
 
 public void createNotification(Context context, String payload) {
  NotificationManager notificationManager = (NotificationManager) context
    .getSystemService(Context.NOTIFICATION_SERVICE);
  Notification notification = new Notification(R.drawable.icon,
    "Message received", System.currentTimeMillis());
  notification.defaults |= Notification.DEFAULT_VIBRATE;
  notification.defaults |= Notification.DEFAULT_SOUND;
  notification.defaults |= Notification.DEFAULT_LIGHTS;
  
  notification.flags |= Notification.FLAG_AUTO_CANCEL;

  if (payload.toLowerCase().contains("chat request")) {

   Intent intent = new Intent(context, L2STest.class);
   intent.putExtra("message", payload);
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   
   PendingIntent pendingIntent = PendingIntent.getActivity(context.getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
   notification.setLatestEventInfo(context, payload,
     "New message received", pendingIntent);
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   notificationManager.notify(0, notification);
   notificationManager.notify(1, notification);
  } else {

   Intent intent = new Intent(context.getApplicationContext(), L2STest.class);
   intent.putExtra("message", payload);
   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
   PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
     intent, PendingIntent.FLAG_ONE_SHOT
       | PendingIntent.FLAG_UPDATE_CURRENT);
   notification.setLatestEventInfo(context, payload,
     "New message received", pendingIntent);
   intent.setAction("android.intent.action.MAIN");
   intent.addCategory("android.intent.category.LAUNCHER");
   notificationManager.notify(0, notification);
   notificationManager.notify(1, notification);
  }

  notification.defaults |= Notification.DEFAULT_SOUND;

  notification.flags |= Notification.FLAG_AUTO_CANCEL;

 }

 
}

 

Revise this Paste

Your Name: Code Language: