由网友(摘星)分享简介:我目前已经有两个活动。一个用于从SD卡,一个用于蓝牙连接拉动图像I have currently have got two activities. One for pulling the image from the SD card and one for Bluetooth connection.我已经利用一个包...
我目前已经有两个活动。一个用于从SD卡,一个用于蓝牙连接拉动图像
I have currently have got two activities. One for pulling the image from the SD card and one for Bluetooth connection.
我已经利用一个包从活动1传输图像的URI。
I have utilized a Bundle to transfer the Uri of the image from activity 1.
现在我希望做的就是让该URI在蓝牙活动,并将其转化为通过字节数组可传输的状态,我已经看到了一些例子,但我似乎无法让他们为我的code !
Now what i wish to do is get that Uri in the Bluetooth activity to and convert it into a transmittable state via Byte Arrays i have seen some examples but i can't seem to get them to work for my code!!
Bundle goTobluetooth = getIntent().getExtras();
test = goTobluetooth.getString("ImageUri");
是我穿过去拉它,什么是下一个步骤?
is what i have to pull it across, What would be the next step?
非常感谢
杰克
推荐答案
在乌里
获得字节[]
我做下面的事情,
From Uri
to get byte[]
I do the following things,
InputStream iStream = getContentResolver().openInputStream(uri);
byte[] inputData = getBytes(iStream);
和的GetBytes(InputStream中)
的方法是:
public byte[] getBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
return byteBuffer.toByteArray();
}
相关推荐
最新文章