自分の写真/ビデオをFacebookにアップロードしようとしていますが、2つ以上の写真、ビデオ、またはそれらの組み合わせをアップロードしようとすると、メモリの問題が発生します。私のデバイスはHTCDesireです:
Publishvideo
public void publishVideo( Bundle kParameters) {
final String kDataPath = kParameters.getString( "video");
kParameters.remove( "picture");
kParameters.remove( "video");
byte[] yData = null;
InputStream kInputStream = null;
try {
kInputStream = new FileInputStream( kDataPath);
yData = readBytes( kInputStream);
kParameters.putString( "token",
ms_kFacebookClient.getAccessToken());
kParameters.putByteArray( "video", yData);
AsyncFacebookRunner kAsyncRunner = new AsyncFacebookRunner( m_kFacebookClient);
kAsyncRunner.request( "me/videos",
kParameters,
"POST",
new RequestListener(),
null);
} catch ( FileNotFoundException e) {
e.printStackTrace();
FacebookX.ms_bIsUploading = false;
} catch ( IOException e) {
e.printStackTrace();
FacebookX.ms_bIsUploading = false;
} catch ( OutOfMemoryError e){
e.printStackTrace();
FacebookX.ms_bIsUploading = false;
}
}
ピクチャー:
public void publishLocalPicture( Bundle kParameters) {
byte[] yData = null;
final String kDataPath = kParameters.getString( "picture");
kParameters.remove( "picture");
kParameters.remove( "video");
kParameters.remove( "filename");
try {
Bitmap kBitmap = BitmapFactory.decodeFile( kDataPath);
ByteArrayOutputStream kByteArrayOutputStream = new ByteArrayOutputStream();
kBitmap.compress( Bitmap.CompressFormat.JPEG,
100,
kByteArrayOutputStream);
yData = kByteArrayOutputStream.toByteArray();
kParameters.putString( "token",
ms_kFacebookClient.getAccessToken());
kParameters.putByteArray( "picture", yData);
AsyncFacebookRunner kAsyncRunner = new AsyncFacebookRunner( m_kFacebookClient);
kAsyncRunner.request( "me/photos",
kParameters,
"POST",
new RequestListener(),
null);
} catch ( OutOfMemoryError e) {
e.printStackTrace();
FacebookX.ms_bIsUploading = false;
}
}
リードバイト:
public byte[] readBytes( InputStream kInputStream) throws IOException {
ByteArrayOutputStream kByteBuffer = new ByteArrayOutputStream();
int iBufferSize = 1024;
byte[] yBuffer = new byte[iBufferSize];
int iLenght = 0;
while ( ( iLenght = kInputStream.read( yBuffer) ) != -1) {
kByteBuffer.write( yBuffer, 0, iLenght);
}
return kByteBuffer.toByteArray();
}