Alljoyn 如何利用Raw格式传输文件
这里的利用到了demo中的RawClient和RawService。请参考SDK。下面的是demo中传输一个字符串所采用的方式:
if(mStreamUp ==true)后面的代码改写为如下的函数即可。
private void doSendFile(){ Log.i(TAG,"doSendFile()"); if(mStreamUp == true){ try{ String filepath = "/sdcard/Teste.jpg"; file = newFile(filepath); mOutputStream.write(getBytesFromFile(file)); mOutputStream.flush(); }catch(Exception ex) { Log.i(TAG,"ERRO writing file "+ex); } } } public byte[] getBytesFromFile(File file) throwsIOException { Log.i(TAG,"getBytesFromFile()"); InputStream is = newFileInputStream(file); longlength = file.length(); if(length > Integer.MAX_VALUE) { System.out.println("Arquivo muito grande"); } byte[] bytes = newbyte[(int) length]; intoffset = 0; intnumRead = 0; while(offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >=0) { offset += numRead; } if(offset < bytes.length) { thrownewIOException("Could not completely read file " + file.getName()); } is.close(); returnbytes; }