Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so dont bother with any of their useless mail servers here and just use oauth login instead. Thank the nice Russians for causing that. :)
Paste
Pasted as Java by registered user neetika ( 14 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.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.sound = Uri.withAppendedPath(
// Audio.Media.INTERNAL_CONTENT_URI, "6");
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, 0,
// intent, PendingIntent.FLAG_ONE_SHOT
// | PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 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);
}
else {
Intent intent = new Intent(context, 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);
}
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
}
private Intent getIntent() {
// TODO Auto-generated method stub
return null;
}
}
Revise this Paste