Android audio transmit with Base64 based on XMPP
2016-05-19 17:16
387 查看
Base64 encode:
private String filePathToString(String filePath) { byte[] audioBytes; String audioString=""; try { ByteArrayOutputStream baos=new ByteArrayOutputStream(); FileInputStream fis= null; fis = new FileInputStream(new File(filePath)); byte[] buf=new byte[1024]; int n; while (-1!=(n=fis.read(buf))) baos.write(buf,0,n); audioBytes=baos.toByteArray(); audioString= Base64.encodeToString(audioBytes, Base64.DEFAULT); } catch (Exception e) { e.printStackTrace(); } return audioString; }
Base64 decode:
private String stringToFilePath(String fileString) throws IOException { byte[] bytesFile=Base64.decode(fileString,Base64.DEFAULT); String decodedString=new String(bytesFile); File file = null; try { String fileName=generateFileName(); file = new File(Environment.getExternalStorageDirectory() + "/"+fileName); FileOutputStream fos = new FileOutputStream(file, true); fos.write(bytesFile); fos.close(); }catch (Exception e) { e.printStackTrace(); } return file.getAbsolutePath(); }
Reference:
How to get an audio file and encode to base64 string相关文章推荐
- Android 录像保存后在文件管理或相册里不显示问题
- android中CheckBox自定义样式
- Android View体系(十)自定义组合控件
- Android全局获取Context
- AndroidStudio插件GsonFormat
- Android 自定义一款炫酷的加载控件
- Android自定义控件三部曲文章索引
- Android视频播放器横竖屏自动切换
- Android中的Drawable使用
- Android一键换肤功能:一种简单的实现
- Android Studio 运行java程序
- Android一键换肤功能:一种简单的实现
- 学习android零碎知识点笔记 preference【转载】
- Android button边框线,只定义一个边框的颜色
- Android 使用NineOldAndroids实现绚丽的ListView左右滑动删除Item效果
- 浅析Android中的消息机制
- Android打开各种文件
- Android--百度地图定位功能的具体实现<百度地图SDK版本 v3.7.3>
- android——彻底关闭——应用程序
- Android.mk 语法