如何在Feed对话框中显示SD卡图像

时间:2013-09-12 11:37:47

标签: android facebook sd-card facebook-android-sdk android-facebook

我正在编写一个程序,我允许用户在他们的[朋友和朋友]上发布消息和图像。用户] Wall,我正在使用SD卡图像发布,但每当我看到我的Feed对话框代替我的SD卡图像时,我都会收到Google的徽标,因为在链接参数中我使用了www.google.com,所以它正在选择图片,见下文:

enter image description here

我尝试了一些其他网络链接,发现它正在从该链接中挑选任何图像....

所以我的问题,为什么我没有获得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" />

2 个答案:

答案 0 :(得分:0)

嘿,为什么不尝试绝对路径

String myPath = sdcardEnvironment.getExternalStorageDirectory().getAbsolutePath() + "/Pictures/Facebook/flower1.jpg";

另请检查您是否在外部读写

的清单文件中提供了权限

试试这个

答案 1 :(得分:0)

Feed对话框不支持上传图片,只允许您为“picture”参数提供网址。

请在此处查看完整文档:https://developers.facebook.com/docs/reference/dialogs/feed/