录音分享以及重命名功能小结
2012-06-06 20:26 htc开发 阅读(299) 评论(0) 编辑 收藏 举报1 录音通过短信分享
String mfname=arr.get(menuInfo.position).get("audioname");//通过contextMenu得到文件名称
String afile = "/sdcard/recorder" + "/" + mfname;//得到存入数据库的录音文件的绝对地址,必须与存入时相匹配。
ContentResolver resolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Cursor c = resolver.query(base, new String[]{"_id"}, MediaStore.Audio.Media.DATA + "='" +afile+"'", null, null);//从数据库中查询
Uri finalUri = null;
if(null != c) {
c.moveToFirst();
int rowId = c.getInt(0);
finalUri=ContentUris.withAppendedId(Audio.Media.getContentUri(base.getPathSegments().get(0)), rowId);//从id中得到URI
c.close();
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, finalUri);
intent.setType("audio/*");
startActivity(Intent.createChooser(intent, SoundRecorderList.this.getResources().getText(R.string.choose_send_client)));
2 录音重命名
public void renameSampleFile(File samFile,String name) {
if (samFile != null && mState != RECORDING_STATE && mState != PLAYING_STATE) {
if (!TextUtils.isEmpty(name)) {
String oldName = samFile.getAbsolutePath();
String extension = oldName.substring(oldName.lastIndexOf('.'));
File newFile = new File(samFile.getParent() + "/" + name + extension);
if (!TextUtils.equals(oldName, newFile.getAbsolutePath())) {
if (samFile.renameTo(newFile)) {
samFile = newFile;
}
}
}
}
}