我正在编写一个程序,在该程序中,我允许用户在他们的 [朋友和用户] 墙上发布消息以及图像,并且我正在使用 SD 卡图像进行发布,但是每当我看到我的提要对话框代替我的 SD 卡时图片我正在获取 Google 的徽标,因为在链接参数中我使用了 www.google.com,所以它选择了该图片,见下文:
我尝试了其他一些网络链接,发现它正在从该链接中选择任何图像......
所以这是我的问题,为什么我没有在那里获得 SD 卡图像
public void onItemClick(AdapterView<?> adapterView, View view,
final int position, long id) {
try {
friendId = jsonArray.getJSONObject(position).getLong("uid");
String name = jsonArray.getJSONObject(position).getString("name");
new AlertDialog.Builder(this)
.setTitle(R.string.post_on_wall_title)
.setMessage(
String.format(getString(R.string.post_on_wall),
name)).setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,int which) {
try
{
String myPath = Environment.getExternalStorageDirectory()
.getAbsolutePath() + "/Pictures/Facebook/flower1.jpg";
File f = new File(myPath);
FileInputStream fis = new FileInputStream(f);
Log.d("onItemClick", "fis ::--" + fis);
Bitmap bi = BitmapFactory.decodeStream(fis);
Log.d("onItemClick", "bi ::--" + bi);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Log.d("onItemClick", "baos ::--" + baos);
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Log.d("onItemClick", "data ::--" + data);
} catch (FileNotFoundException e) {
e.printStackTrace();
Log.d("onCreate", "debug error e = " + e.toString());
}
Bundle params = new Bundle();
params.putString("to", String.valueOf(friendId));
params.putString("caption", getString(R.string.app_name));
params.putString("description", getString(R.string.app_desc));
params.putString("link", "http://www.google.com");
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
Log.d("onItemClick", "params.putByteArray ::--" + data);
params.putString("name", getString(R.string.app_action));
FacebookUtility.facebook.dialog(FriendsList.this, "feed",
params, (DialogListener) newPostDialogListener());
}
}).setNegativeButton(R.string.no, null).show();
} catch (JSONException e) {
showToast("Error: " + e.getMessage());
}
}
我也在Manifest 中给予了这些许可:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />