【问题标题】:Firebase handleIntent AbstractMethodErrorFirebase 处理意图 AbstractMethodError
【发布时间】:2017-08-23 03:56:42
【问题描述】:

当我在 Android 上收到推送通知时,我收到以下错误。我似乎无法找到任何有关它的信息。任何人都可以帮忙吗?我真的很茫然。

致命异常:pool-1-thread-1 进程:com.mycompany.myerror,PID: 22712 java.lang.AbstractMethodError:抽象方法“无效” com.google.firebase.iid.zzb.handleIntent(android.content.Intent)”在 com.google.firebase.iid.zzb$1.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 在 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);
                }
            }
        }
}

【问题讨论】:

    标签: android firebase push-notification firebase-cloud-messaging


    【解决方案1】:

    您应该保持 Firebase 库版本和 Google Play 服务库相似。所以将 Firebase 库的版本号更新为 10.2.1:

    变化:

    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'
    

    【讨论】:

    • @user-44651 这是你的问题的答案吗?
    • 当我有一个依赖于 com.google.firebase:firebase-messaging:10.2.0 的库和一个依赖于 com.google.firebase:firebase-core:10.2.1 的库时,这对我有用。将依赖项添加到消息传递:10.2.1 在这里解决了我的问题。
    • 类似包下的所有库版本都应该匹配,请接受这个作为正确答案
    【解决方案2】:

    我刚刚清理了项目,它工作了

    【讨论】:

      【解决方案3】:

      您必须在同一版本中拥有每个 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'
      

      【讨论】:

      • 别问我为什么……它甚至解决了一些顽固的编译难题。根本就没有handleIntent。奇怪,因为应该在 10 上定义它,在 11 上它应该被定义......这对他们来说破坏编译兼容性并不典型,但是......事实说话。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多