아래에 샘플을 설명하고 문제를 이해하는 데 도움이되는 최소한의 코드를 제공합니다. 내 종속 {} 내가Firebase가 알림을 위해 작동하지 않습니다.
compile 'com.google.firebase:firebase-messaging:9.2.0'
을 추가 한 내부 끝에 내 Gradle을 파일에
,
apply plugin: 'com.google.gms.google-services'
는 또한 종속 {}
compile 'com.google.android.gms:play-services:9.2.0'
compile 'com.google.android.gms:play-services-maps:9.2.0'
compile 'com.google.android.gms:play-services-ads:9.2.0'
compile 'com.google.android.gms:play-services-auth:9.2.0'
compile 'com.google.android.gms:play-services-gcm:9.2.0'
compile 'com.google.android.gms:play-services-analytics:9.2.0'
compile 'com.google.android.gms:play-services-location:9.2.0'
compile 'com.google.maps.android:android-maps-utils:0.4.+'
에 다음이 내가 가지고있는 매니 페스트
<!-- Google Cloud Messaging -->
<uses-permission
android:name="com.mcruiseon.buseeta.permission.C2D_MESSAGE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<service android:name=".support.NotificationIncoming">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name=".support.NotificationsIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
NotificationIncoming.java은 내가
- 수행 한 중포 기지에 내 NotificationIDService
public class NotificationsIDService extends FirebaseInstanceIdService { @Override public void onTokenRefresh() { String refreshedToken = FirebaseInstanceId.getInstance().getToken(); Log.d(God.LOG_TAG, "Refreshed token: " + refreshedToken); sendRegistrationToServer(refreshedToken); } private void sendRegistrationToServer(String token) { // Add custom implementation, as needed. } }
에서
public class NotificationIncoming extends FirebaseMessagingService { @Override public void onMessageReceived(RemoteMessage remoteMessage) { Log.d(God.LOG_TAG, "From: " + remoteMessage.getFrom()); Log.d(God.LOG_TAG, "Notification Message Body: " + remoteMessage.getNotification().getBody()); sendNotification(remoteMessage.getNotification().getBody()); } private void sendNotification(String messageBody) { Intent intent = new Intent(this, MyBookings.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent, PendingIntent.FLAG_ONE_SHOT); Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) //.setSmallIcon(R.drawable.ic_launcher) .setContentTitle("FCM Message") .setContentText(messageBody) .setAutoCancel(true) .setSound(defaultSoundUri) .setContentIntent(pendingIntent); NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(0 /* ID of notification */, notificationBuilder.build()); } }
있다
- google-services.json을 다운로드하여 앱 폴더에 복사했습니다.
SHA1과 동일한 키 저장소에서 서명 된 응용 프로그램을 만들었습니다. 그리고 응용 프로그램을 실행하십시오. 그런 다음 Firebase 콘솔에서 메시지를 보냈습니다.
행운을 비네. 내가 뭘 놓치고 있니? 정말로 기본적인 것. 이 글을 읽는 모든 분들을 위해
편집
는, 위에서 완벽하게 나를 위해 일했습니다.
는 콘솔에 드롭 다운 존재에서 응용 프로그램 패키지 이름을 선택하고 BTW'있습니까 <사용-허가 안드로이드 : 이름 = "com.mcruiseon.buseeta.permission.C2D_MESSAGE을" 안드로이드 : protectionLevel = "서명"/> <사용 권한 android : name = "com.google.android.c2dm.permission.RECEIVE"/>'는 더 이상 필요하지 않습니까? –
예. 웬일인지 많은 알림이 늦게 받았다. – Siddharth