通知通知时发生 TransactionTooLargeException

2024-04-04

我在 android 中录制时有更新时间,我使用 CountDownTimer 并根据通知更新到远程视图。我已经优化了最小的 数据但仍然得到 TransactionTooLargeException。

public void showNotificationRecording() {
    mRemoteViews = new RemoteViews(getPackageName(), R.layout.notify_recording_layout);
    mBuilder = new NotificationCompat.Builder(mContext);
    isSecretModeEnable = mSharePreferencesSettings.getBoolean(RecordSettings.SECRET_MODE, false);
    Log.d(TAG, "isSecretModeEnable " + isSecretModeEnable);
    if (isSecretModeEnable) {
        mRemoteViews = new RemoteViews(getPackageName(), R.layout.notify_secret_mode_layout);
        mBuilder.setPriority(Notification.PRIORITY_MIN)
                .setSmallIcon(R.drawable.ic_notify_secret)
                .setContent(mRemoteViews);

        // Save File Notification
        Intent mIntentSave = new Intent(mContext, RecordAudioService.class);
        mIntentSave.setAction(ACTION_STOP_RECORD);
        PendingIntent mSavePendingIntent = PendingIntent.getService(mContext, 0, mIntentSave, 0);
        mRemoteViews.setOnClickPendingIntent(R.id.iv_notify_save, mSavePendingIntent);
    } else {
        mRemoteViews = new RemoteViews(getPackageName(), R.layout.notify_recording_layout);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
        }
        mBuilder.setSmallIcon(R.drawable.record_circle)
                .setPriority(Notification.PRIORITY_MAX)
                .setDefaults(Notification.DEFAULT_LIGHTS)
                .setContent(mRemoteViews);

        Intent notificationIntent = new Intent(this, MainActivity.class);
        PendingIntent mMainPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        mBuilder.setContentIntent(mMainPendingIntent);

        mRemoteViews.setTextViewText(R.id.tv_notify_time, mRecordTimeNotification);
        // Pause and Resume Notification
        Intent mIntentPauseAndResume = new Intent(mContext, RecordAudioService.class);
        mIntentPauseAndResume.setAction(ACTION_PAUSE_AND_RESUME);
        PendingIntent mPauseAndResumePending = PendingIntent.getService(mContext, 0, mIntentPauseAndResume, 0);
        mRemoteViews.setOnClickPendingIntent(R.id.iv_notify_pause_and_resume, mPauseAndResumePending);
        // Save File Notification
        Intent mIntentSave = new Intent(mContext, RecordAudioService.class);
        mIntentSave.setAction(ACTION_STOP_RECORD);
        PendingIntent mSavePendingIntent = PendingIntent.getService(mContext, 0, mIntentSave, 0);
        mRemoteViews.setOnClickPendingIntent(R.id.iv_notify_save, mSavePendingIntent);
        //Delete Notification
        Intent mIntentDelete = new Intent(mContext, RecordAudioService.class);
        mIntentDelete.setAction(ACTION_NOTIFICATION_DISCARD);
        PendingIntent mDeletePendingIntent = PendingIntent.getService(mContext, 0, mIntentDelete, 0);
        mRemoteViews.setOnClickPendingIntent(R.id.iv_notify_closed, mDeletePendingIntent);

        if (isRecording) {
            mRemoteViews.setImageViewResource(R.id.iv_notify_pause_and_resume, R.drawable.ic_notify_pause);
            mState = mContext.getString(R.string.recording_state);
            mRemoteViews.setTextViewText(R.id.tv_notify_status, mState);
        } else {
            mRemoteViews.setImageViewResource(R.id.iv_notify_pause_and_resume, R.drawable.ic_notify_record);
            mState = mContext.getString(R.string.pause_state);
            mRemoteViews.setTextViewText(R.id.tv_notify_status, mState);
        }
    }

    isShowNotification = true;
    mNotificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
    startForeground(NOTIFICATION_ID, mBuilder.build());
}
public CountDownTimer countDownRecordingTime() {
    CountDownTimer time;
    time = new CountDownTimer(Long.MAX_VALUE, 250) {

        @Override
        public void onTick(long millisUntilFinished) {
            final Integer convertToSecond = mCountTimer / 4;
            if (mTime != convertToSecond) {
                mTime = convertToSecond;
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        showTimeRecording(mTime);
                    }
                });
            }
            mCountTimer++;

            // check when user setting timer
            if (mTimerToEnd != 0 && mTimerToEnd == convertToSecond) {
                onStopRecording();
            }
        }

        @Override
        public void onFinish() {

        }
    };
    return time;
}

我更新通知如下,我只更新时间记录到通知。

private void showTimeRecording(int convertToSecond) {
    int hours = convertToSecond / 3600;
    int minutes = (convertToSecond % 3600) / 60;
    int seconds = convertToSecond % 60;
    mRecordTime = String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, seconds);
    mRecordTimeNotification = mRecordTime;

    mRemoteViews.setTextViewText(R.id.tv_notify_time, mRecordTimeNotification);
    if (!mState.equals(mContext.getString(R.string.recording_state))) {
        mState = mContext.getString(R.string.recording_state);
        mRemoteViews.setTextViewText(R.id.tv_notify_status, mState);
    }
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}

请帮我解决这个问题。


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通知通知时发生 TransactionTooLargeException 的相关文章

随机推荐

  • 多个 Eclipse 项目中的多个 Git 分支

    我们正在从 Subversion 转换到 Git 而我在 Git 中遇到的一件事是切换分支的方法 我的理解是 无论是在命令行还是在 Eclipse 中使用 EGit 切换到不同的分支都会将 Eclipse 工作区文件夹的内容替换为所需分支的
  • Redirect::back() 在 Laravel 5.2 中不起作用

    if count data 1 return view welcome else echo dslkfjads Redirect back gt with message Username or password not Match 上述
  • 两个日期之间的月份差异

    C 如何计算两个日期之间的月份差异 有没有相当于VB的DateDiff C 中的方法 我需要找出相隔数年的两个日期之间的月份差异 文档说我可以使用TimeSpan like TimeSpan ts date1 date2 但这给了我以天为单
  • Python 2.5:XML 中的 ElementTree 和 UML

    我正在使用一个代表 UML 模型的 XML 文件 下面是一个例子
  • Couchbase N1QL 联接查询

    需要 Couchbase 环境中的查询帮助 文档1和文档2都在同一个桶中 首先 查询将使用以下查询获取文档 message1 SELECT uid message sent by FROM bucket USE KEYS message1
  • Composer 需要 phpoffice/phpspreadsheet 不起作用

    我想使用 Phpspreadsheet 包编写一个脚本 我没有 php 经验 我正在尝试通过 sudo Composer require phpoffice phpspreadsheet 添加对我的脚本的引用 但这不起作用 我收到错误 安装
  • Mac Lion 上架构 x86_64 ImageMagick 的未定义符号

    在 Mac Lion 上 我完成了配置 制作并安装了 ImageMagick 的静态版本 一切顺利 作为配置的结果 我得到了 configuring ImageMagick 6 7 2 4 checking build system typ
  • 从 Perl 中的字符串中删除换行符

    我有一个从文本文件读取的字符串 但在 Ubuntu Linux 中 我尝试从末尾删除其换行符 我用了所有的方法 但对于s n r 我看看它是否找到任何替换任何新行字符串 它替换了字符串 但当我打印它时它仍然转到下一行 此外 当我使用chom
  • VueJS 获取 Div 的宽度

    我有一个 Vue 组件 它使用引导网格 在子组件中 我想获取控制器中某个 div 的当前宽度 这是子组件
  • 如何克服 Selenium 中的 Element id 异常?

    T 在 UiBinder 本身中为 GWT 小部件设置 id For eg 还添加了在 gwt xml 中 然后我在 Selenium 测试用例中尝试这个 WebElement element driver findElement By i
  • 为什么java TreeMap基于红黑树的实现?

    第三段维基百科关于 AVL 树的文章 http en wikipedia org wiki AVL tree说 因为 AVL 树更加严格平衡 所以对于查找密集型应用程序来说 它们比红黑树更快 所以 不应该TreeMap http docs
  • 具有递归类型参数的泛型类型以及抽象 self 方法如何允许方法链正常工作?

    我在读有效的 Java 版本 3 在第 2 章第 14 页中 作者讨论了构建器模式并呈现了以下代码 public abstract class Pizza public enum Topping HAM MUSHROOM ONION PEP
  • Java:获取对象的唯一哈希值

    我正在尝试获取Java对象的唯一哈希值 如下所示 If A B then A HashValue B Hash HashValue If A B then A HashValue B HashValue 假设该对象包含几个布尔值和整数字段
  • @angular-builders - 在优化阶段忽略某些脚本

    我需要让 Angular 忽略某个js文件在优化阶段 这样它就不会被优化 缩小 prod建造 为此目的 angular builders包似乎是一个可行的解决方案 我设置了angular json配置如下 architect build b
  • Android:如何通过 ueventd.rc 向设备授予 666 权限

    我需要访问连接到我的 已root Android 的USB 摄像头 我使用的是运行 Android 4 2 2 的三星 Galaxy S4 我想用普通的应用程序访问它 所以我需要该设备是世界可读的 我可以通过 shell 进行连接并输入 r
  • 读取Excel文件时如何识别单元格为空白或为空或为空

    我读取了一个 Excel 文件来传递某些数据字段的输入 但是当我运行该程序时 某些单元格值返回为 null 某些单元格值返回为空白 实际上 当我打开 Excel 文件时 单元格中没有可用值 如何手动识别 Excel 单元格为空或空白 对于某
  • PHP:为什么只能通过引用传递变量?

    如果您是 PHP 开发人员 您很可能看到过以下通知 注意 在 somefile php 中只有变量应该通过引用传递 在线 xxx 问题广泛处理于只有变量应该通过引用传递 https stackoverflow com questions 4
  • 更新属性文件的更好的类?

    Though java util properties允许读写属性文件 写入时不保留格式 这并不奇怪 因为它与属性文件无关 有没有PropertyFile那里的类 或类似的类 保留注释和空行并更新属性值 它没有比 Apache 的 Comm
  • SQLAlchemy 中的 VALUES 子句

    有没有办法建立一个QuerySQLAlchemy 中的对象相当于 SELECT FROM VALUES 1 2 3 AS sq 从我在文档中看到的 VALUES子句仅出现在与INSERT 现在 这在 SQLAlchemy 中本身就可用 您的
  • 通知通知时发生 TransactionTooLargeException

    我在 android 中录制时有更新时间 我使用 CountDownTimer 并根据通知更新到远程视图 我已经优化了最小的 数据但仍然得到 TransactionTooLargeException public void showNoti