android - 如何允许用户使用 SDCard 文件夹在墙上张贴图像

标签 android facebook android-layout facebook-graph-api facebook-android-sdk

我允许用户在他们的 [Friend & User] Wall 上发布消息 以及单个静态图像,对于该图像我正在使用 Web图片网址

但现在我希望允许用户从多张图片中选择任意一张,比如存储在 SDCard 中特定文件夹中的 10 张图片,然后发布到墙上

那么这是我的问题,该怎么做?

我现有的在墙上发布静态图片的代码,请阅读以下内容:

@Override
public void onClick(DialogInterface dialog, int which) {

        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("picture",FacebookUtility.HACK_ICON_URL);
            params.putString("name",getString(R.string.app_action));

            FacebookUtility.facebook.dialog(FriendsList.this,
           "feed", params, (DialogListener) new PostDialogListener());
      }
  }).setNegativeButton(R.string.no, null).show();
 } catch (JSONException e) {
      showToast("Error: " + e.getMessage());
}

FacebookUtility.java:-

public static final String HACK_ICON_URL = "http://2.bp.blogspot.com/-WuasmTMjMA4/TY0SS4TzIMI/AAAAAAAAFB4/6alyfOzWsqM/s320/flowers-wallpapers-love-blooms-roses-bunch-of-flowers.jpg";

检查我的应用的现有屏幕,

enter image description here

正如您在上面的屏幕中看到的那样,我只显示了我上面写的单个静态图像,但现在我想让用户使用 SD 卡从多个图像中选择一个图像,我的 SDCard 路径喜欢:/sdcard/FbImages/

现在我想知道如何在屏幕上方放置按钮 [因为我没有为此使用任何自定义 xml,这是 FacebookSDK 中的原生功能]

所以这是我的问题如何打开 sdcard 文件夹以及如何从多张图片中选择要发布的单张图片

最佳答案

您必须找到该图像的路径。

尝试使用下面的代码来选择图片

btnSelect.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
             Intent intent = new Intent();
             intent.setType("image/*");
             intent.setAction(Intent.ACTION_GET_CONTENT);
             startActivityForResult(Intent.createChooser(intent,"Select Picture"), 0);
        }
    });

获取所选图片的路径

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == 0) {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
            System.out.println("Image Path : " + selectedImagePath);

        }
    }
}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

然后使用

  params.putString("picture",selectedImagePath);

关于android - 如何允许用户使用 SDCard 文件夹在墙上张贴图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18657388/

相关文章:

Android Geocoder 返回空地址

Facebook 分享和点赞按钮显示相同的计数 - 这是不对的

java - IntelliJ IDEA 14 在哪里可以获得 Android Designer?

javascript - Facebook Graph API 没有提供实际的用户 ID

Android - 按钮上的 9patch 填充

java - 在 Eclipse 中将线性布局中的文本居中对齐?

android - 对字符串 android 的 HttpResponse

java - 从数组构建列表并允许列表可单击

java - 如何修复错误 YouTubeInitializationResult.SERVICE_INVALID

facebook - HTTPS 而非 HTTP 中的 CakePHP Facebook 插件错误