Android 如何在提要对话框中显示SD卡图像
我正在编写一个程序,允许用户在[Friend&user]墙上发布消息和图像,我使用SD卡图像发布,但每当我看到我的订阅源对话框代替SD卡图像时,我就会看到谷歌的徽标,因为在link参数中我使用了www.Google.com,所以它会选择该图像,请参见下文: 我尝试了其他一些网络链接,发现它正在从该链接中拾取任何图像 所以我的问题是,为什么我没有在那里得到SD卡图像Android 如何在提要对话框中显示SD卡图像,android,facebook,sd-card,facebook-android-sdk,android-facebook,Android,Facebook,Sd Card,Facebook Android Sdk,Android Facebook,我正在编写一个程序,允许用户在[Friend&user]墙上发布消息和图像,我使用SD卡图像发布,但每当我看到我的订阅源对话框代替SD卡图像时,我就会看到谷歌的徽标,因为在link参数中我使用了www.Google.com,所以它会选择该图像,请参见下文: 我尝试了其他一些网络链接,发现它正在从该链接中拾取任何图像 所以我的问题是,为什么我没有在那里得到SD卡图像 public void onItemClick(AdapterView<?> adapterView, View vi
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());
}
}
public void onItemClick(AdapterView AdapterView,View,
最终整数位置,长id){
试一试{
friendId=jsonArray.getJSONObject(position.getLong(“uid”);
String name=jsonArray.getJSONObject(position.getString(“name”);
新建AlertDialog.Builder(此)
.setTitle(R.string.post\u on\u wall\u title)
.setMessage(
格式(getString(R.String.post_on_wall),
名称)).setPositiveButton(R.string.yes,
新建DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
尝试
{
字符串myPath=Environment.getExternalStorageDirectory()
.getAbsolutePath()+“/Pictures/Facebook/flower1.jpg”;
文件f=新文件(myPath);
FileInputStream fis=新的FileInputStream(f);
Log.d(“onItemClick”,“fis::-”+fis);
位图bi=BitmapFactory.decodeStream(fis);
Log.d(“onItemClick”,“bi::-”+bi);
ByteArrayOutputStream bas=新的ByteArrayOutputStream();
Log.d(“onItemClick”,“baos::-”+baos);
压缩(位图.CompressFormat.JPEG,100,baos);
data=baos.toByteArray();
Log.d(“onItemClick”,“data::-”+data);
}catch(filenotfound异常){
e、 printStackTrace();
Log.d(“onCreate”,“debug error e=“+e.toString());
}
Bundle params=新Bundle();
params.putString(“to”,String.valueOf(friendId));
参数putString(“标题”,getString(R.string.app_name));
参数putString(“说明”,getString(R.string.app_desc));
参数putString(“链接”http://www.google.com");
参数putString(“方法”,“照片上传”);
参数putByteArray(“图片”,数据);
Log.d(“onItemClick”,“params.putByteArray::-”+数据);
参数putString(“name”,getString(R.string.app_action));
facebook.facebook.dialog(FriendsList.this,“提要”,
参数,(DialogListener)newPostDialogListener());
}
}).setNegativeButton(R.string.no,null).show();
}捕获(JSONException e){
showToast(“错误:+e.getMessage());
}
}
我也在清单中给予了这些许可:
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE" />
嘿,为什么不试试绝对路径
String myPath = sdcardEnvironment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/Facebook/flower1.jpg";
还要检查您是否在清单文件中为外部读写提供了权限
试试这个提要对话框不支持上传图像,它只允许您为“picture”参数提供url 请参见此处的完整文档: