2015-01-03 4 views
0

이 튜토리얼/예제를 따라 가며 대부분 잘 작동합니다. https://developer.android.com/google/gcm/client.html#app타블렛에서 알림 메시지가 표시되지 않는 이유는 무엇입니까?

웹 서비스가 알림을 발송하는 시점. 올바른 메시지와 함께 알림 전달 방법으로 전달됩니다. 문제는 내가 태블릿에 대한 실제 알림을 보지 못한다는 것입니다 (최신 Android 버전이 아니라 Android 2의 새로운 버전이기도합니다).

다음은 내 sendNotification의 모습입니다. 어떤 아이디어? 앱에서 하나의 활동이 있으며 중요한 경우 여기에 "MainActivity"가 있습니다.

private void sendNotification(String msg) { 
     mNotificationManager = (NotificationManager) 
       this.getSystemService(Context.NOTIFICATION_SERVICE); 

     PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
       new Intent(this, MainActivity.class), 0); 

     Intent resultIntent = new Intent(this, MainActivity.class); 
     TaskStackBuilder stackBuilder = TaskStackBuilder.create(this); 
     stackBuilder.addParentStack(MainActivity.class); 
     stackBuilder.addNextIntent(resultIntent); 

     NotificationCompat.Builder mBuilder = 
       new NotificationCompat.Builder(this) 
         //.setSmallIcon(R.drawable.ic_stat_gcm) 
         .setContentTitle("My Messages") 
         .setStyle(new NotificationCompat.BigTextStyle() 
           .bigText("test")) 
         .setContentText("Test"); 

     mBuilder.setContentIntent(contentIntent); 
     mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 
} 
+0

이 코드가 실행되고 있습니까? IMHO에는 분명히 잘못된 것이 없습니다. – CommonsWare

+0

나는 그곳에서 디버깅을 할 수 있으며, 모든 것이 잘 보입니다. 나는 안드로이드/알림을 처음 사용합니다. 오른쪽 상단에서 당기기를하면 나타납니다. – Maestro1024

+4

[docs] (http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CreateNotification) setSmallIcon()이 필요합니다. –

답변

1

Notifications Guide에 따르면 통지해야합니다 setContentText() 설정 setContentTitle()

  • 상세 텍스트로 설정 setSmallIcon()
  • 제목 설정 작은 아이콘, 적어도

    그래서 setSmallIcon()이 필요합니다.

    설명서에 언급되지 않은 내용은 누락 된 내용이 있으면 경고없이 자동으로 작동하지 않는다는 것입니다.

  • 관련 문제