【测试步骤】
短信添加录音附件,录音
【测试结果】
没有录音时间限制,超出彩信最大限制也正常录音
【预期结果】
应该有录音时间限制
首先分析是否因在彩信中没有没有在Intent中封装彩信剩余大小,定位到ComposeMessageActivity类的addAttachment()方法中:
private void addAttachment(int type, boolean replace) {
// Calculate the size of the current slide if we‘re doing a replace so the
// slide size can optionally be used in computing how much room is left for an attachment.
int currentSlideSize = 0;
SlideshowModel slideShow = mWorkingMessage.getSlideshow();
if (replace && slideShow != null) {
WorkingMessage.removeThumbnailsFromCache(slideShow);
SlideModel slide = slideShow.get(0);
currentSlideSize = slide.getSlideSize();
}
switch (type) {
case AttachmentTypeSelectorAdapter.ADD_IMAGE:
MessageUtils.selectImage(this, REQUEST_CODE_ATTACH_IMAGE);
break;
case AttachmentTypeSelectorAdapter.TAKE_PICTURE: {
MessageUtils.capturePicture(this, REQUEST_CODE_TAKE_PICTURE);
break;
}
case AttachmentTypeSelectorAdapter.ADD_VIDEO:
MessageUtils.selectVideo(this, REQUEST_CODE_ATTACH_VIDEO);
break;
case AttachmentTypeSelectorAdapter.RECORD_VIDEO: {
long sizeLimit = computeAttachmentSizeLimit(slideShow, currentSlideSize);
if (sizeLimit > 0) {
MessageUtils.recordVideo(this, REQUEST_CODE_TAKE_VIDEO, sizeLimit);
} else {
Toast.makeText(this,
getString(R.string.message_too_big_for_video),
Toast.LENGTH_SHORT).show();
}
}
break;
case AttachmentTypeSelectorAdapter.ADD_SOUND:
MessageUtils.selectAudio(this, REQUEST_CODE_ATTACH_SOUND);
break;
case AttachmentTypeSelectorAdapter.RECORD_SOUND:
long sizeLimit = computeAttachmentSizeLimit(slideShow, currentSlideSize);
MessageUtils.recordSound(this, REQUEST_CODE_RECORD_SOUND, sizeLimit);
break;
case AttachmentTypeSelectorAdapter.ADD_SLIDESHOW:
editSlideshow();
break;
case AttachmentTypeSelectorAdapter.ADD_CONTACT_AS_TEXT:
pickContacts(MultiPickContactsActivity.MODE_INFO,
replace ? REQUEST_CODE_ATTACH_REPLACE_CONTACT_INFO
: REQUEST_CODE_ATTACH_ADD_CONTACT_INFO);
break;
case AttachmentTypeSelectorAdapter.ADD_CONTACT_AS_VCARD:
pickContacts(MultiPickContactsActivity.MODE_VCARD,
REQUEST_CODE_ATTACH_ADD_CONTACT_VCARD);
break;
default:
break;
}
}
从以上代码中发现,这里的Intent中已经封装了彩信剩余大小的控制,因此该问题进入录音机界面进行分析:
经过分析发现,录音机应用并没有从Intent中取出对录音文件大小的控制。
修改方法:LemediaRecorder类的onCreate中进行修改:
public void onCreate(Bundle icycle) {
super.onCreate(icycle);
stopRecorder();
mSharedPreferences = getSharedPreferences("storage_Path", Context.MODE_PRIVATE);
mPrefsStoragePathEditor = mSharedPreferences.edit();
mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Intent i = getIntent();
if (i != null) {
intentRecorder = true;
final String EXTRA_MAX_BYTES
= android.provider.MediaStore.Audio.Media.EXTRA_MAX_BYTES;
mMaxFileSize = i.getLongExtra(EXTRA_MAX_BYTES, -1);
}
if (AUDIO_ANY.equals(mRequestedType) || ANY_ANY.equals(mRequestedType)) {
mRequestedType = AUDIO_AMR;
}
mPath = mSharedPreferences.getInt("path", mPath);
//mRequestedType = mSharedPreferences.getString("requestedType", mRequestedType);
mRequestedType = AUDIO_AMR;
//mFileType = mSharedPreferences.getInt("fileType", mFileType);
mFileType = 0;
mStoragePath = mSharedPreferences.getString("storagePath", mStoragePath);
if (!mWAVSupport && mRequestedType == AUDIO_WAVE_2CH_LPCM) {
mRequestedType = AUDIO_AMR;
mFileType = 0;
}
setContentView(R.layout.main);
mAudioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
mRecorder = new Recorder();
mRecorder.setOnStateChangedListener(this);
mRemainingTimeCalculator = new RemainingTimeCalculator(LemediaRecorder.this);
PowerManager pm
= (PowerManager) getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,
"LemediaRecorder");
initResourceRefs();
mRecorderStop = false;
mDataExist = false;
setResult(RESULT_CANCELED);
registerExternalStorageListener();
if (icycle != null) {
Bundle recorderState = icycle.getBundle(RECORDER_STATE_KEY);
if (recorderState != null) {
mRecorder.restoreState(recorderState);
mSampleInterrupted = recorderState.getBoolean(SAMPLE_INTERRUPTED_KEY, false);
mMaxFileSize = recorderState.getLong(MAX_FILE_SIZE_KEY, -1);
int showAndExit = recorderState.getInt(DIALOG_STATE_KEY);
mLastFileName = recorderState.getString(LAST_FILE_NAME_KEY);
if (showAndExit != -1) showDialogAndExit(showAndExit == 1);
}
}
mTelephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
mPhoneStateListener = getPhoneStateListener();
String ssrRet = mAudioManager.getParameters("ssr");
if (ssrRet.contains("=true")) {
bSSRSupported = true;
} else {
bSSRSupported = false;
}
updateUi();
}
问题OK,搞定!
解决:短信添加录音附件,录音,没有录音时间限制,超出彩信最大限制也正常录音,布布扣,bubuko.com