I'm an android newbie, so please be patient!
Finally, I got my XML result from a simple WCF REST API via GCM wishing to build a simple notification with its payload.
@Override
protected void onMessage(Context arg0, Intent arg1) {
String message = arg1.getStringExtra("payload");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification();
note.tickerText=message;
note.when=System.currentTimeMillis();
note.defaults |= Notification.DEFAULT_ALL;
notificationManager.notify(new Random().nextInt(), note);
}
I'm hearing my default notification sound but my bar isn't showing anything, What I'm missing?
EDIT I
Note:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="17" />
I tried Jeeter suggestion about building the notification up with the builder, however a MINIMUM API 16 is required which isn't good + my Galaxy note test device is 4.0.4 which is API 15!
@Override
protected void onMessage(Context arg0, Intent arg1) {
String Message = arg1.getStringExtra("payload");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(
new Random().nextInt(),
new Notification.Builder(this)
.setContentTitle(Message)
.setContentText(Message).build());
}
public Notification build ()
Added in API level 16
Combine all of the options that have been set and return a new
Notification object.
EDIT II
I tried A--C suggestion about using NotificationCompat builder.
@Override
protected void onMessage(Context arg0, Intent arg1) {
String Message = arg1.getStringExtra("payload");
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(
new Random().nextInt(),
new NotificationCompat.Builder(this).setContentTitle("Message")
.setWhen(System.currentTimeMillis())
.setDefaults(Notification.DEFAULT_ALL)
.setContentText(Message).build());
}
No errors but nothing changed, I still hear sound with no appearance, however the message reached the onMessage method.