19

जब मुझे एंड्रॉइड पर पुश अधिसूचना मिलती है, तो मुझे निम्न त्रुटि मिलती है। मुझे वास्तव में इसके बारे में कोई जानकारी नहीं मिल रही है। क्या कोई मदद कर सकता है? मैं वास्तव में एक नुकसान में हूँ।फायरबेस हैंडेंट इंटेंट सार MethodError

FATAL EXCEPTION: pool-1-thread-1 Process: com.mycompany.myerror, PID: 22712 java.lang.AbstractMethodError: abstract method "void com.google.firebase.iid.zzb.handleIntent(android.content.Intent)" at com.google.firebase.iid.zzb$1.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) at 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())); 

    } 

उपयोगिताएँ

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()); 
     } 

HomeActivity

@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); 
       } 
      } 
     } 
} 

उत्तर

50

आपको फायरबेस लाइब्रेरीज़ संस्करण और Google Play सेवाएं लाइब्रेरी को समान रखना चाहिए। तो 10.2.1 के Firebase libararies की संस्करण संख्याओं को अद्यतन:

बदलें:

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' 
+0

@ उपयोगकर्ता -44651 क्या यह आपका प्रश्न है? –

+0

यह मेरे लिए काम करता था जब मेरे पास com.google.firebase के आधार पर एक lib था: फायरबेस-मैसेजिंग: 10.2.0 और com.google.firebase पर एक: firebase-core: 10.2.1। संदेश पर निर्भरता जोड़ना: 10.2.1 ने मेरी समस्या का समाधान यहां किया। –

+0

समान पैकेजों के तहत सभी लाइब्रेरी संस्करणों को मेल खाना चाहिए, कृपया इसे सही उत्तर के रूप में स्वीकार करें – Manny265

1

मैं सिर्फ परियोजना साफ किया और यह

11

Yout चाहिए काम किया प्रत्येक Google Play सेवा की लाइन को उसी संस्करण में

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' 
+0

मुझसे मत पूछें क्यों ... यह कुछ जिद्दी संकलन गूढ़ व्यक्ति को भी हल करता है। हैंडेंट इन्टेंट बिल्कुल याद नहीं था। अजीब क्योंकि 10 पर इसे परिभाषित किया जाना चाहिए, 11 पर इसे परिभाषित किया जाना चाहिए ... संकलन संगतता को तोड़ने के लिए उनके लिए विशिष्ट नहीं है, और फिर भी ... तथ्य बोलते हैं। – Meymann