我有一个正在开发的应用程序,可以将图片上传到 Facebook 相册。该应用程序可以正常上传照片,没有问题。如果我对照片进行硬编码,我也可以在照片上添加标题。我要做的是制作一个警报对话框,该对话框将捕获用户标题,然后在上传图片之前将其放入捆绑包中。发生的事情是照片被上传,然后我得到对话框来输入标题。
这是弹出警报对话框的方法...
public String createAlert() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Enter Caption for Photo");
alert.setMessage("Caption :");
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
imageCaption = input.getText().toString();
return;
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
return;
}
});
AlertDialog helpDialog = alert.create();
helpDialog.show();
return imageCaption;
}
现在这里是捆绑包并上传到 facebook...
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case PICK_EXISTING_PHOTO_RESULT_CODE: {
if (resultCode == RESULT_OK){
Uri photoUri = data.getData();
String imagePath = getPath(photoUri);
byte[] data1 = null;
Bitmap bi = BitmapFactory.decodeFile(imagePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data1 = baos.toByteArray();
Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("caption", createAlert() );
params.putByteArray("photo", data1);
try {
facebook.request("me/photos",params,"POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
}
default: {
facebook.authorizeCallback(requestCode, resultCode, data);
break;
}
}
}