Lorsque je reçois une notification Push sur Android, j'obtiens l'erreur ci-dessous. Je n'arrive pas vraiment à trouver aucune information à ce sujet. Quelqu'un peut-il aider? Je suis vraiment perdue.
EXCEPTION FATALE: pool-1-thread-1 Processus: com.mycompany.myerror, PID: 22712 Java.lang.AbstractMethodError: méthode abstraite "void Com.google.firebase.iid.zzb.handleIntent (Android.content.Intent)" à com.google.firebase.iid.zzb $ 1.run (source inconnue) à l'adresse Java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.Java:1113) à Java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.Java:588) sur Java.lang.Thread.run (Thread.Java:818)
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.Android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.Android.support', module: 'support-annotations'
})
compile 'com.Android.support:multidex:1.0.1'
compile 'com.Android.support:appcompat-v7:25.3.0'
compile 'com.Android.support:support-v4:25.3.0'
compile 'com.Android.support:design:25.3.0'
//https://developers.google.com/Android/guides/setup
compile 'com.google.Android.gms:play-services-places:10.2.1'
compile 'com.google.Android.gms:play-services-maps:10.2.1'
compile 'com.google.Android.gms:play-services-location:10.2.1'
compile 'com.google.Android.gms:play-services-vision:10.2.1'
compile 'com.google.Android.gms:play-services-gcm:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.google.zxing:core:3.2.0'
compile 'com.journeyapps:zxing-Android-embedded:3.5.0'
compile 'com.loopj.Android:android-async-http:1.4.9'
testCompile 'junit:junit:4.12'
}
FirebaseMessagingService.Java
public class FirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FCM Service";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
super.onMessageReceived(remoteMessage);
try {
sendNotification(remoteMessage);
} catch (Exception e) {
e.printStackTrace();
}
}
private void sendNotification(final RemoteMessage remoteMessage) throws Exception {
Calendar calendar = Calendar.getInstance();
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
String strDate = sdf.format(c.getTime());
String contentTitle = "New Push Message";
String contentText = "Received at " + strDate;
Utilities.sendNotification(getApplicationContext(),
getNotificationIcon(),
contentTitle,
contentText,
0,
HomeActivity.class,
Utilities.getNotificationId(getApplicationContext()));
}
Utilitaires
public static void sendNotification(Context appContext,
int icon,
String title,
String msg,
long when,
Class<? extends Context> classToLaunch,
long processId) {
//Define notification msg
Intent launchIntent = null;
if (classToLaunch != null) {
launchIntent = new Intent(appContext, classToLaunch);
} else {
launchIntent = new Intent();
}
// This is dummy data for just differentiate Pending intent
// only set value that is check IntentFilter
launchIntent.addCategory("CATEGORY" + new Date(System.currentTimeMillis()));
launchIntent.addFlags((int) System.currentTimeMillis());
launchIntent.setAction("ACTION" + new Date(System.currentTimeMillis()));
// also make launch mode to singleTop in manifest for that activity
launchIntent.setFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK |
Intent.FLAG_ACTIVITY_NEW_TASK);
// intent to be launched when click on notification
PendingIntent pendingIntent = PendingIntent.getActivity(appContext,
0,
launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
//Instantiate the notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(appContext); //(icon, msg, when);
builder.setContentTitle(title);
builder.setSmallIcon(icon);
builder.setWhen(when);
builder.setTicker(msg);
builder.setContentText(msg);
builder.setContentIntent(pendingIntent);
builder.setAutoCancel(true);
builder.setDefaults(Notification.DEFAULT_LIGHTS);
builder.setDefaults(Notification.DEFAULT_SOUND);
NotificationManager notificationManager = (NotificationManager) appContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify((int) processId, builder.build());
}
AccueilActivité
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
if (getIntent().getExtras() != null) {
for (String key : getIntent().getExtras().keySet()) {
Object value = getIntent().getExtras().get(key);
if (BuildConfig.DEBUG_APPLICATION) {
Log.d(TAG, "Key: " + key + " Value: " + value);
}
}
}
}
Vous devez conserver la version des bibliothèques Firebase et des bibliothèques de services Google Play identiques. Mettez donc à jour les numéros de version des bibliothèques Firebase vers 10.2.1:
Changement:
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'
À:
compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'
Vous devez avoir toutes les lignes de services Google Play dans la même version.
compile 'com.google.Android.gms:play-services:11.0.1'
compile 'com.google.Android.gms:play-services-maps:11.0.1'
compile 'com.google.firebase:firebase-core:11.0.1'
compile 'com.google.firebase:firebase-messaging:11.0.1'
Je viens de nettoyer le projet et cela a fonctionné