마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

GCM 사용중인데 앱단에서 푸시 메시지를 받지 못합니다

0 추천

얼마전까지만 해도 잘 사용해왔는데 웹단에서는 에러 없이 잘 보내는 걸 확인했는데

앱단에서 메시지 받았을 때 GCMIntentService 클래스를 호출하지 않습니다.

  public GcmIntentService()
  {
    super("GcmIntentService");
  }
  
  
  @Override
  protected void onHandleIntent(Intent intent)
  {
    Bundle extras = intent.getExtras();
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
    // The getMessageType() intent parameter must be the intent you received
    // in your BroadcastReceiver.
    String messageType = gcm.getMessageType(intent);
    
    if (!extras.isEmpty())
    { // has effect of unparcelling Bundle
      /*
       * Filter messages based on message type. Since it is likely that GCM will
       * be extended in the future with new message types, just ignore any
       * message types you're not interested in, or that you don't recognize.
       */
      if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType))
      {
       //sendNotification("Send error: " + extras.toString());
      }
      else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType))
      {
        //sendNotification("Deleted messages on server: " + extras.toString());
        // If it's a regular GCM message, do some work.
      }
      else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType))
      {
        String msg = intent.getStringExtra("msg");

          // Post notification of received message.
//            sendNotification("Received: " + extras.toString());
        sendNotification(intent);
        Log.i("GcmIntentService", "Received: " + extras.toString());
      }
    }
    // Release the wake lock provided by the WakefulBroadcastReceiver.
    GcmBroadcastReceiver.completeWakefulIntent(intent);
  }
  
  
  // Put the message into a notification and post it.
  // This is just one simple example of what you might choose to do with
  // a GCM message.
  private void sendNotification(Intent intents)
  {
    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    String title = intents.getStringExtra("title");
    String msg = intents.getStringExtra("msg");
    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("title", title);
    intent.putExtra("msg", msg);
    intent.putExtra("eventcode", intents.getStringExtra("eventcode"));
    
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.mipmap.ic_launcher).setContentTitle(title).setStyle(
        new NotificationCompat.BigTextStyle().bigText(msg)).setContentText(msg).setAutoCancel(true).setVibrate(new long[] { 0, 500 });
    
    mBuilder.setContentIntent(contentIntent);
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
  }

현재 소스인데 메시지 받았을 때 sendNotification(intent);를 호출해야 되는데

디버깅 해봐도 전혀 타질 않네요

문제가 있나요?

아니면 혹시 GCM 변경된 정책같은게 있나요?

새로 등록해야된다던가..

양꼬양 (2,040 포인트) 님이 2015년 9월 8일 질문

1개의 답변

0 추천
 
채택된 답변

http://mydevromance.tistory.com/38

구글링하니 바로 나오네요.

onStartCommand() 커맨드를 구현하랍니다

익명사용자 님이 2015년 9월 8일 답변
양꼬양님이 2015년 9월 8일 채택됨
...