FB Cloud Messaging funktioniert nicht
Ich versuche zu zeigen, eine Benachrichtigung auf meine Bewerbung. Ich habe eine Anwendung auf der FB-Konsole. Hinweis: Es gibt keine Fehler. Wenn Sie die Anwendung starten, nachdem ich dann eine Nachricht über FB-Konsole nichts angezeigt wird. Was ist hier falsch?
MyFireBaseInstaceIDService.java
package com.example.hp.mesajlasma;
import android.util.Log;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.FirebaseInstanceIdService;
public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService {
private static final String TAG = "MyFirebaseIIDService";
/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
//[START refresh_token]
@Override
public void onTokenRefresh() {
//Get updated InstanceID token.
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
//If you want to send messages to this application instance or
//manage this apps subscriptions on the server side, send the
//Instance ID token to your app server.
sendRegistrationToServer(refreshedToken);
}
//[END refresh_token]
/**
* Persist token to third-party servers.
*
* Modify this method to associate the user's FCM InstanceID token with any server-side account
* maintained by your application.
*
* @param token The new token.
*/
private void sendRegistrationToServer(String token) {
//TODO: Implement this method to send token to your app server.
}
}
MyFireBaseMessagingService.java
package com.example.hp.mesajlasma;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
/*** Created by Belal on 5/27/2016.*/
public class MyFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "MyFirebaseMsgService";
/**
* Called when message is received.
*
* @param remoteMessage Object representing the message received from Firebase Cloud Messaging.
*/
//[START receive_message]
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
//[START_EXCLUDE]
//There are two types of messages data messages and notification messages. Data messages are handled
//here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
//traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
//is in the foreground. When the app is in the background an automatically generated notification is displayed.
//When the user taps on the notification they are returned to the app. Messages containing both notification
//and data payloads are treated as notification messages. The Firebase console always sends notification
//messages. For more see: https://firebase.google.com/docs/cloud-messaging/concept-options
//[END_EXCLUDE]
Log.d(TAG, "From: " + remoteMessage.getFrom());
//Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
//Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
//Also if you intend on generating your own notifications as a result of a received FCM
//message, here is where that should be initiated. See sendNotification method below.
}
//[END receive_message]
/**
* Create and show a simple notification containing the received FCM message.
*
* @param messageBody FCM message body received.
*/
private void sendNotification(String messageBody) {
Intent intent = new Intent(this, MainActivity.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.common_google_signin_btn_icon_dark_focused)
.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());
}
}
build.gradle
//Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0-alpha5'
classpath 'com.google.gms:google-services:3.0.0'
//NOTE: Do not place your application dependencies here; they belong
//in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
AndroidManifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.hp.mesajlasma">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!--
Defining Services
-->
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service
android:name=".MyFirebaseInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
</application>
</manifest>
build.gradle
(app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "com.example.hp.mesajlasma"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha5'
testCompile 'junit:junit:4.12'
compile 'com.google.firebase:firebase-messaging:9.0.0'
}
apply plugin: 'com.google.gms.google-services'
Blick auf diesen link und akzeptieren Sie die Antwort, wenn es bekommt, dass es funktioniert. stackoverflow.com/questions/37997957/...
Hinzugefügt habe ich die Erlaubnis, aber es funktioniert immer noch nicht. es macht mich verrückt...
Wussten Sie, fügen Sie die
was verwenden Sie als Ziel von der Konsole aus? Haben Sie versucht, den Versand der Instanz-ID-token generiert der FB-messaging? Auch ich würde vorschlagen, mit v 9.4.0
Frage mich, ob du eine Lösung gefunden...
Hinzugefügt habe ich die Erlaubnis, aber es funktioniert immer noch nicht. es macht mich verrückt...
Wussten Sie, fügen Sie die
google-services.json
- Datei zu Ihrem Projekt?was verwenden Sie als Ziel von der Konsole aus? Haben Sie versucht, den Versand der Instanz-ID-token generiert der FB-messaging? Auch ich würde vorschlagen, mit v 9.4.0
Frage mich, ob du eine Lösung gefunden...
InformationsquelleAutor Hüseyin YILMAZ | 2016-08-09
Du musst angemeldet sein, um einen Kommentar abzugeben.
Alle Dateien sieht gut aus, außer MyFireBaseMessaginService.java
Vergleichen Sie es mit mir tun und änderungen und es sollte funktionieren.
Stellen Sie außerdem sicher, dass Sie sich registriert haben, Ihre app auf FCM-Konsole und generiert googleservices.json nach Eingabe Ihrer app package name.
MainActivity.java
FireBaseInstanceIDService.java
überprüfen Sie Ihre logcat. sind Sie immer Token gibt es? Wie es scheint, ist nur Beispiel-Projekt von GooGleQuickStart? Wenn das der Fall ist, stellen Sie sicher, melden Sie sich Projektes auf FCM-Konsole, und erhalten Sie Ihren eigenen googleservices.json und fügen Sie ihn in den app-Verzeichnis des Projekts
08-09 17:13:20.877 3163-4348/com.Beispiel.PS.mesajlasma D/FirebaseInstanceId: hintergrund-Synchronisierung fehlgeschlagen: MISSING_INSTANCEID_SERVICE, wiederholen in 160s
WENN ICH EINE NACHRICHT GESENDET, ES GIBT DIESE.
08-09 17:10:50.807 3163-3189/com.Beispiel.PS.mesajlasma W/InstanceID/Rpc: Fehler zu beheben, REGISTRIEREN Sie die Absicht, wieder zurück zu fallen 08-09 17:10:50.811 3163-3189/com.Beispiel.PS.mesajlasma W/InstanceID/Rpc: Beide Google-Play-Services und legacy-GSF-Paket fehlen 08-09 17:10:50.811 3163-3179/com.Beispiel.PS.mesajlasma I/FA: Dieses Beispiel markiert als uploader
InformationsquelleAutor Raj
Machen einfacher Prozess für FB Benachrichtigung.
Download Beispiel-code von unten link :
https://github.com/firebase/quickstart-android
(es ist 100% arbeiten)
Zur Prüfung Meldung:
Gehen Sie zu FB-Konsole - > wählen Sie Ihre Anwendung
Wählen Sie Mitteilungen-Sektion -> Klicken Sie auf Neue Nachricht und fügen Sie Ihre Nachricht ein und klicken Sie auf Nachricht Senden.
InformationsquelleAutor ViramP
Für die Einstellung der FCM, wie beschrieben in Einrichten der Feuerstellung und der FCM SDK, der erste Schritt, Staaten zu hinzufügen Feuerstellung auf Ihrem Android-Projekt.
Müssen Sie
compile 'com.google.firebase:firebase-core:9.4.0'
(entsprechende version also 9.0, wenn Sie bevorzugen ältere version, so dass es keine Unstimmigkeiten, ich habe die neueste version jetzt), wenn Sie befolgt haben zusammen alle weiteren Schritte zum hinzufügen von FB zu Ihrer app.InformationsquelleAutor student
Nur import FB-messaging in Ihrem Projekt.
Sie müssen dieses add line in-app-Modul gradle-Datei.
InformationsquelleAutor Kamal Bunkar