使用GCM服務從節點js服務器發送消息,設備中的服務被接收到服務中,最後顯示在通知中。所有作品和設備都會收到通知,但是,當我想要創建通知時,它不會顯示通知。我很失落,也許我錯過了關於通知創建的內容。我正在用google提供的gcm示例來指導自己,儘管我不能顯示通知。從服務創建通知
這裏是服務的代碼:
public class MyGcmListenerService extends GcmListenerService {
private static final String TAG = "MyGcmListenerService";
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("TableMeNot");
Log.d(TAG, "From: " + from);
Log.d(TAG, "Message: " + message);
sendNotification(message);
}
private void sendNotification(String message) {
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle("You have a new notification!!!")
.setContentText(message)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.notify(1, notificationBuilder.build());
Log.d(TAG, "NOTIFICATION CREATED!!!!!!!!!!!!!!!");
}
感謝您的幫助。
請問你的服務器端代碼的樣子?你如何發送通知? –