我在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());
}
请帮我解决这个问题。