gpt4 book ai didi

java - 从包发布的错误通知,无法展开 RemoteViews

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:44 25 4
gpt4 key购买 nike

08-23 13:42:57.649: E/AndroidRuntime(3836): FATAL EXCEPTION: main
08-23 13:42:57.649: E/AndroidRuntime(3836): android.app.RemoteServiceException: Bad notification posted from package com.test.nursery.rhymes.stories: Couldn't expand RemoteViews for: StatusBarNotification(pkg=com.test.nursery.rhymes.stories id=16104475 tag=null score=0 notn=Notification(pri=0 contentView=com.test.nursery.rhymes.stories/0x7f030012 vibrate=null sound=null defaults=0x4 flags=0x10 kind=[null]))
08-23 13:42:57.649: E/AndroidRuntime(3836): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1471)
08-23 13:42:57.649: E/AndroidRuntime(3836): at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 13:42:57.649: E/AndroidRuntime(3836): at android.os.Looper.loop(Looper.java:153)
08-23 13:42:57.649: E/AndroidRuntime(3836): at android.app.ActivityThread.main(ActivityThread.java:5000)
08-23 13:42:57.649: E/AndroidRuntime(3836): at java.lang.reflect.Method.invokeNative(Native Method)
08-23 13:42:57.649: E/AndroidRuntime(3836): at java.lang.reflect.Method.invoke(Method.java:511)
08-23 13:42:57.649: E/AndroidRuntime(3836): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
08-23 13:42:57.649: E/AndroidRuntime(3836): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
08-23 13:42:57.649: E/AndroidRuntime(3836): at dalvik.system.NativeStart.main(Native Method)

当我在应用程序未运行时发送推送通知时,任何人都可以帮助我遇到这样的问题。请任何人帮助...此问题的代码已按要求提供。还想了解远程 View 的详细概念。我试图从开发者网站研究它。但不能在那里得到更好的解释。也请为此粘贴一些有用的链接。

代码如下:

long when = System.currentTimeMillis();
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(res_icon, message, when);

Intent notificationIntent = new Intent(context, FisrtActivityClass);
notificationIntent.putExtra("message", message);

notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context,
notificationid, notificationIntent, 0);
MyLog.d(TAG, custom_layout_id + "; text");
try {
// create custom notification view
MyLog.d(TAG, "layout = " + custom_layout_id + "; image = "
+ custom_image_id + "; text = " + custom_text_id);
RemoteViews contentView = new
RemoteViews(context.getApplicationContext().getPackageName(),
custom_layout_id);
contentView.setImageViewResource(custom_image_id, res_icon);
contentView.setTextViewText(custom_text_id, message);
notification.contentView = contentView;
notification.contentIntent = contentIntent;

notification.setLatestEventInfo(context, title, message,
contentIntent);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
notification.setLatestEventInfo(context, title, message,
contentIntent);
}

notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notificationManager.notify(notificationid, notification);

最佳答案

尝试使用 Notification.Builder 而不是 Notification。例如:

Notification.Builder builder = new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_launcher)
.setContent(remoteViews);

对于未决的 Intent ,试试这个:

Notification notification = builder.build();
notification.contentView.setOnClickPendingIntent(R.id.button, pendinglIntent);

关于java - 从包发布的错误通知,无法展开 RemoteViews,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25459977/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com