现在我正在开发一个 Android 应用程序。在我的应用程序中,我必须将图片从我的画廊提交到 facebook。我使用了以下代码。
if (item == 1) {
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (resultCode != RESULT_OK) return;
Bitmap bitmap = null;
if (requestCode == PICK_FROM_FILE) {
mImageCaptureUri = data.getData();
mPath = getRealPathFromURI(mImageCaptureUri); //from Gallery
if (mPath == null){
mPath = mImageCaptureUri.getPath(); //from File Manager
}
if (mPath != null) {
System.out.println("mpath is not null"+mPath);
bitmap = BitmapFactory.decodeFile(mPath);
}
}
}
private void postToFacebook(String desc){
AsyncFacebookRunner mAsyncFbRunner = new AsyncFacebookRunner(mFacebook);
Bundle params = new Bundle();
try {
params.putByteArray("photo",
Utility.scaleImage(getApplicationContext(),mImageCaptureUri));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
params.putString("caption", desc);
mAsyncFbRunner.request("me/photos", params, "POST",
new PhotoUploadListener());
}
它在模拟器中对我来说工作正常,但在真实设备图像中没有发布。但没有崩溃。请帮助我的朋友