Firebase handleIntent AbstractMethodError [英] Firebase handleIntent AbstractMethodError

查看:1809
本文介绍了Firebase handleIntent AbstractMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Android上收到推送通知时,出现以下错误。我似乎无法找到任何有关它的信息。谁能帮忙?


$ b


致命例外:pool-1-thread-1进程:com.mycompany.myerror,PID:
22712 java.lang.AbstractMethodError:抽象方法void
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)
at
java.util.concurrent.ThreadPoolExecutor $ Worker.run( ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)



 依赖关系{
编译fileTree(包括:['* .jar'],dir:'libs')
androidTestCompile('com.android.support.test.espresso:espresso -core:2.2.2',{
exclude group:'com.android.support',module:'support-annotations'
})
compile'c​​om.android.support:multidex :1.0.1'
compile'c​​om.android.support:appcompat-v7:25.3 .0'
compile'c​​om.android.support:support-v4:25.3.0'
compile'c​​om.android.support:design:25.3.0'
// https:/ /developers.google.com/android/guides/setup
compile'c​​om.google.android.gms:play-services-places:10.2.1'
compile'c​​om.google.android.gms: play-services-maps:10.2.1'
compile'c​​om.google.android.gms:play-services-location:10.2.1'
compile'c​​om.google.android.gms:play- services-vision:10.2.1'
compile'c​​om.google.android.gms:play-services-gcm:10.2.1'
compile'c​​om.google.firebase:firebase-messaging:10.0。 1'
compile'c​​om.google.firebase:firebase-core:10.0.1'
compile'c​​om.squareup.picasso:picasso:2.5.2'
compile'c​​om.google。 zxing:core:3.2.0'
compile'c​​om.journeyapps:zxing-android-embedded:3.5.0'
compile'c​​om.loopj.android:android-async-http:1.4.9'
testCompile'junit:junit:4.12'
}


$ b

FirebaseMessagingService.java

  public class FirebaseMessagingService extends FirebaseMessagingService {

private static final String TAG =FCM Service;

@Override
public void onMessageReceived(RemoteMessage remoteMessage){
super.onMessageReceived(remoteMessage);
尝试{
sendNotification(remoteMessage);
} catch(Exception e){
e.printStackTrace();
}




private void sendNotification(final RemoteMessage remoteMessage)throws Exception {

Calendar calendar = Calendar。的getInstance();
日历c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(h:mm a);
String strDate = sdf.format(c.getTime());

字符串contentTitle =新推消息;
String contentText =Received at+ strDate;

Utilities.sendNotification(getApplicationContext(),
)getNotificationIcon(),
contentTitle,
contentText,
0,
HomeActivity.class,
Utilities.getNotificationId(getApplicationContext()));

$ b

实用程序


$ b $ pre $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
long when,
Class< ;? extends Context> classToLaunch,
long processId){

//定义通知msg
意图launchIntent = null;

if(classToLaunch!= null){
launchIntent = new Intent(appContext,classToLaunch);
} else {
launchIntent = new Intent();
}

//这是虚拟数据,用于区分待定意图
//仅设置值,即检查IntentFilter
launchIntent.addCategory(CATEGORY+ new日期(System.currentTimeMillis的()));
launchIntent.addFlags((int)System.currentTimeMillis());
launchIntent.setAction(ACTION+ new Date(System.currentTimeMillis()));

//也将启动模式设置为singleTop在该活动的清单中
launchIntent.setFlags(
Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK |
意图.FLAG_ACTIVITY_NEW_TASK);

//意图在点击通知时启动
PendingIntent pendingIntent = PendingIntent.getActivity(appContext,
0,
launchIntent,
PendingIntent.FLAG_UPDATE_CURRENT );

//实例化通知
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 $ b

  @Override 
保护无效的onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
$ b $ if(getIntent()。getExtras()!= null){
(String key:getIntent()。getExtras()。keySet()){
Object value getIntent()。getExtras()。get(key);
if(BuildConfig.DEBUG_APPLICATION){
Log.d(TAG,Key:+ key +Value:+ value);



$ b $ / code $ / pre

解决方案

您应该保持Firebase libraties版本和Google Play服务库类似。因此,请将Firebase版本库的版本更新至10.2.1:

更改:

  compile'c​​om.google.firebase:firebase-core:10.0.1'
compile'c​​om.google.firebase:firebase-messaging:10.0.1'
  compile'c​​om。 google.firebase:firebase-core:10.2.1'
compile'c​​om.google.firebase:firebase-messaging:10.2.1'


When I receive a push notification on Android, I get the below error. I can't really seem to find any information about it. Can anyone help? I am really at a loss.

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

    }

Utilities

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

解决方案

You should keep the Firebase libraties version and Google play services libraries similar. So update the version numbers of the Firebase libararies to 10.2.1:

Change:

compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-messaging:10.0.1'

To:

compile 'com.google.firebase:firebase-core:10.2.1'
compile 'com.google.firebase:firebase-messaging:10.2.1'

这篇关于Firebase handleIntent AbstractMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆