- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在编写一个 Android 应用程序来跟踪用户的位置并在通知中显示行程的距离、时间和价格,所有这些都在 ForegroundService
中进行跟踪。该服务跟踪位置、价格和时间,我每秒更新一次通知。我在第一次通知更新的生产中遇到了这个 TransactionTooLargeException
,它只发生在运行 Android 8.0+ 的三星设备上。
这是正在发生的事情:
我从服务中调用 start
方法:
public void start(MeasureService service) {
service.startForeground(NOTIFICATION_ID, getNotification(0, 0, 0));
}
我从服务调用 update
方法:
public void update(int price, float meters, long time) {
mNotificationManager.notify(NOTIFICATION_ID, getNotification(price, meters, time));
}
实际上,这些调用是一个接一个地调用的,崩溃来自 update
方法。这(一个接一个地调用它们)会成为问题吗?
这是getNotification
:
private Notification getNotification(int price, float meters, long seconds) {
if (mNotificationBuilder == null) {
createNotificationBuilder();
}
return mNotificationBuilder
.setCustomContentView(getSmallView(price))
.setCustomBigContentView(getBigView(price, seconds, meters))
.build();
}
其中 getSmallView
和 getBigView
方法是这样的:
private RemoteViews getSmallView(int price) {
String priceText = ...;
mSmallView.setTextViewText(R.id.price, priceText);
return mSmallView;
}
private RemoteViews getBigView(int price, long seconds, float meters) {
String priceText = ...;
String timeText = ...;
String distanceText = ...;
mBigView.setTextViewText(R.id.price, priceText);
mBigView.setTextViewText(R.id.time, timeText);
mBigView.setTextViewText(R.id.distance, distanceText);
return mBigView;
}
这就是我创建 notificationBuilder
的方式:
private void createNotificationBuilder() {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, CHANNEL_NAME, NotificationManager.IMPORTANCE_LOW);
((NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
mNotificationBuilder = new NotificationCompat.Builder(mContext, NOTIFICATION_CHANNEL_ID);
mNotificationBuilder = mNotificationBuilder
.setSmallIcon(R.drawable.icon)
.setOngoing(true)
.setContentIntent(getOpenMeasurePageIntent());
}
和getOpenMeasurePageIntent
:
private PendingIntent getOpenMeasurePageIntent() {
Intent launchMeasureIntent = new Intent(mContext, MainActivity.class);
launchMeasureIntent.setAction(...);
launchMeasureIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
return PendingIntent.getActivity(mContext, 0, launchMeasureIntent, 0);
}
这是我得到的崩溃日志:
Caused by: java.lang.RuntimeException: android.os.TransactionTooLargeException: data parcel size 560988 bytes
16 at android.app.NotificationManager.notifyAsUser(NotificationManager.java:319)
17 at android.app.NotificationManager.notify(NotificationManager.java:284)
18 at android.app.NotificationManager.notify(NotificationManager.java:268)
19 at com.myapp.service.measure.MyNotification.void update(int,float,long) <- this is called from the timer
我在网上发现了很多类似的问题,但它们通常是关于在 Intent 中传递大块数据,我相信我没有这样做。
知道我可能做错了什么吗?
最佳答案
我认为问题在于每秒更新一次通知。
解决方案
我建议您仅在数据(距离、价格)发生变化时更新通知。
关于ForegroundService 通知的 android.os.TransactionTooLargeException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51936819/
Exception thrown launching activities in ProcessRecord{3c67ecf8080:com.example/u0a171} android.os.Tr
异常 05-12 15:42:45.791 11043-11043/ E/UncaughtException: java.lang.RuntimeException: android.os.Tran
val intent = Intent(Intent.ACTION_PICK) intent.type = "image/*" val mimeTypes = arrayOf("image/jpeg"
我正在开发一个 Android 项目,但当我需要从图库中拍照时,我遇到了困难。确实,当我拍摄第一张照片时,一切都很顺利。但是,如果我拍摄第二张照片,则会引发异常“TransactionTooLarge
我不知道在我的一个 Fragment Screens 上导致此异常的原因和位置。 我尝试用这个 TooLargeTool 调试它我有这样的输出: 2-19 18:20:24.317 25554 255
这个问题在这里已经有了答案: What to do on TransactionTooLargeException (43 个回答) 关闭 3 年前。 我正在尝试将 parse.com 与我的 an
这个问题在这里已经有了答案: android.os.TransactionTooLargeException on Nougat (13 个答案) 关闭 4 年前。 我开发了一款应用,该应用在 An
作为我的应用程序的一部分,我通过使用 ApplicationPackageManager.getInstalledApplications 获得了设备上安装的应用程序列表,但对于某些用户,我收到的崩溃
我正在使用正常 Intent 启动 Google map ,并启动覆盖按钮服务以返回我的应用程序。 Intent iconServiceIntent = new Intent(MainActivity
我遇到了 TransactionTooLargeException。不可重现。在文档中它说 The Binder transaction failed because it was too large
尝试共享图像文件时,我不断收到此错误: java.lang.RuntimeException:android.os.TransactionTooLargeException:数据包大小1085992字
我正在使用 usb-serial-for-android 库,我得到了一些奇怪的结果。连续2.5小时与串口通信,读写成功,出现如下异常: exception in UsbManager.openDev
我从我的一个实时应用程序中看到了很多错误报告,原因是这个异常: java.lang.RuntimeException: Adding window failed at android.view.
我的应用程序读取所有已安装 APK 文件的列表,然后循环遍历列表以读取 APK 信息,但它会抛出 TransactionTooLargeException 异常。 根据我在这里阅读的内容 http:/
我将 Nexus 5X 更新为 Android N,现在当我在其上安装应用程序(调试或发布)时,我在每个具有 Bundle in extras 的屏幕转换时都会收到 TransactionTooLar
我在Google Play商店中有一个Android游戏是使用Unity 2018.4.2f1和IL2CPP而不是Mono构建的。 使用的运行时版本.Net 3.5,我以ARMv7和ARM64为目标,
我有一个应用程序,用户可以在其中为他们的用户配置文件上传图像。在我的应用程序中,我允许用户使用 native 裁剪器裁剪图像。但是,当我尝试裁剪大图像时,我的 Logcat 中出现以下错误: !!!
我是第一次实现 ViewPager,我遇到了一些问题,因为我收到以下错误: 06-20 10:40:51.366 11377-11377/com.example.ruelas.elite E/Andr
我正在编写一个 Android 应用程序来跟踪用户的位置并在通知中显示行程的距离、时间和价格,所有这些都在 ForegroundService 中进行跟踪。该服务跟踪位置、价格和时间,我每秒更新一次通
我认为 Intent 的额外大小限制是 1MB,如 docs 上所报告的那样.无论如何,我在追逐这个可怕的 TransactionTooLargeException 时迷失了一天: E/JavaBi
我是一名优秀的程序员,十分优秀!