api 24及更高版本的RemoteViews和Picasso问题

时间:2018-12-16 20:46:30

标签: android url notifications picasso remoteview

我使用这些代码行来获取通知,通知是通过Picasso库中的URL加载的

                // Default stuff; making and showing notification
                final Context context = getApplicationContext();
                final NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                final Notification notification = new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.notification_icon) // Needed for the notification to work/show!!
                        .setContentTitle(eventName)
                        .setContentText(eventTime)
                        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.logo))
                        .setStyle(new NotificationCompat.BigPictureStyle())
                        .build();
                final int notifId = 1337;
                notificationManager.notify(notifId, notification);
                final RemoteViews bigContentView = 
                notification.bigContentView;
                final int bigIconId = getResources().getIdentifier("android:id/big_picture", null, null);
Picasso.with(getApplicationContext()).load(imageUrl).into(bigContentView,bigIconId, notifId, notification);
                }

代码在经过多次测试的api 21中工作得很好,但是在api 24之类的高级API上却给出错误提示:“ RemoteViews不能为null。”

完全是错误:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.domain.firebaseapp, PID: 31642
    java.lang.IllegalArgumentException: RemoteViews must not be null.
        at com.squareup.picasso.RequestCreator.into(RequestCreator.java:540)
        at com.domain.firebaseapp.BackgroundService$1.onChildAdded(BackgroundService.java:94)
        at com.google.android.gms.internal.firebase_database.zzbt.zza(Unknown Source)
        at com.google.android.gms.internal.firebase_database.zzgx.zzdr(Unknown Source)
        at com.google.android.gms.internal.firebase_database.zzhd.run(Unknown Source)
        at android.os.Handler.handleCallback(Handler.java:754)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:163)
        at android.app.ActivityThread.main(ActivityThread.java:6238)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)

0 个答案:

没有答案