푸시 알림에 Google 클라우드 메시징 (GCM) 서비스를 사용하려면 첫 번째 Android 앱을 개발하고 있습니다. 필자는 서버 응용 프로그램에서 성공적으로 메시지를 보내고 클라이언트 응용 프로그램의 GCMIntentService 클래스에서 onMessage 이벤트에 메시지 내용을 기록 할 수있게되었습니다. 그러나 메시지가 수신되었다는 표시는 장치에 표시되지 않습니다. 나는 iPhone에서와 마찬가지로 전화로 풀다운 알림 목록에 메시지가 나타날 것으로 예상했다. 이 코드는 수동으로 코딩해야합니까? 또한 어떤 액티비티가 현재 활성화되어 있는지 여부와 앱이 백그라운드에서 유휴 상태인지 여부에 관계없이 메시지를 표시하는 일반적인 방법이 있습니까? 어떤 도움을 주셔서 감사합니다.Android - GCM 푸시 알림이 알림 목록에 표시되지 않음
6
A
답변
7
이 코드는 화면 상단의 Android 시스템 표시 줄에 알림을 생성합니다. 이 코드는 상단 바에서 알림을 클릭 한 후 사용자를 "Home.class"로 안내하는 새로운 의도를 만듭니다. 현재 활동을 기반으로 특정 작업을 수행하려면 GCMIntentService에서 다른 활동으로 브로드 캐스트 요청을 보낼 수 있습니다.
Intent notificationIntent=new Intent(context, Home.class);
generateNotification(context, message, notificationIntent);
private static void generateNotification(Context context, String message, Intent notificationIntent) {
int icon = R.drawable.icon;
long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(icon, message, when);
String title = context.getString(R.string.app_name);
// set intent so it does not start a new activity
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent =PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, title, message, intent);
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(0, notification);
}
이 예제에서는 작동해야하는 R.drawable 및 R.String의 리소스를 사용하지만 아이디어를 제공해야합니다. 상태 알림에 대한 자세한 내용은 http://developer.android.com/guide/topics/ui/notifiers/index.html 및 이에 대한 방송 수신자에 대한 정보를 참조하십시오. 당신이 GcmListenerService를 사용하는 경우 http://developer.android.com/reference/android/content/BroadcastReceiver.html
1
당신은 환상적인 많은 감사의 당신의 onMessageReceived sendNotification에()
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
sendNotification(message);
}
private void sendNotification(String message) {
Intent intent = new Intent(this, YOURCLASS.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_park_notification)
.setContentTitle("Ppillo Message")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}
관련 문제
- 1. android GCM 푸시 알림
- 2. GCM 알림이 표시되지 않습니다.
- 3. 푸시 알림 Asp.net를 사용하여 (알림이 수신되지) (GCM) (브라우저 키)
- 4. 알림 표시 줄에 GCM 알림이 표시되지 않습니다. 안드로이드
- 5. GCM Cordova 푸시 알림이 앱이 실행되지 않을 때 작동하지 않습니다.
- 6. Android에서 푸시 알림 : Google GCM vs. Amazon SNS?
- 7. Windows Phone 7 푸시 알림이 내 전화에서 표시되지 않음
- 8. Google에서 앱을 강제 종료하는 경우 푸시 알림이 작동하지 않음
- 9. 푸시 알림 배포시 작동하지 않음
- 10. iPad에서 푸시 알림이 설정에 표시되지 않습니다.
- 11. PHP 및 Android GCM 푸시 알림 - 사용자 저장 방법
- 12. GCM 푸시 알림 android 3.1 : 브로드 캐스트 리시버 비활성화
- 13. GCM 및 Urban Flyship을 통한 Android 푸시 알림
- 14. 푸시 알림 시작 안드로이드 GCM on
- 15. GCM 푸시 알림 서버 측 asp.net
- 16. Android SDK 웹 푸시 알림?
- 17. WebView에서 Android 푸시 알림?
- 18. Android GCM 등록
- 19. Android 푸시 알림 샘플
- 20. android c2dm 푸시 알림
- 21. APNS 푸시 알림이 잘못됨
- 22. 아이폰 OS 푸시 알림이 - 대신
- 23. 푸시 알림 알림 처리
- 24. 기기는 Android GCM 푸시 알림을 어떻게 받나요?
- 25. Android Gcm ROR과 함께 작동하지 않음
- 26. 아이폰 푸시 알림 Reliefablity
- 27. 푸시 알림 (Push Notification) 위임자가 호출되지 않음
- 28. 사용자가 앱을로드 할 때 알림에 푸시 알림이 표시되지 않습니다.
- 29. 푸시 알림 문제
- 30. 알림 센터에 일부 기기에 앱이 표시되지 않음
에 추가,이 코드를 사용할 수 있습니다. –
안녕하세요, 저는이 플러그인을 https://github.com/marknutter/GCM-Cordova에 사용하고 모든 지침을 따랐습니다. 그러나, 나는 애플 리케이션 내에서만 메시지를 얻을 수 있지만 안드로이드 알림 영역에 알림을 표시하는 응용 프로그램을 얻을 수 없습니다. 제발 조언. 나는이 플러그인을 사용하여 phonegap을 사용합니다. @Zachary Moshansky –
죄송 합니다만 Phonegap을 사용한 적이 없으며 알림 기능을 사용하는 방법에 대해서는 언급 할 수 없습니다. –