如何让用户使用SDCard文件夹在墙上发布图像 [英] How to allow user to post an Image on Wall using SDCard Folder

查看:182
本文介绍了如何让用户使用SDCard文件夹在墙上发布图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户在他们的[Friend&用户]墙沿着单个静态图像,对于该图像,我使用的是 Web Image URL



但现在我希望允许用户从多个图像中选择任何单个图像,例如存储在 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.jpg; 

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





如上图所示,我只能显示单个静态图像,如上所述,但现在我想允许用户使用SD卡,SDCard路径从多张图像中选择一张图像
喜欢: / sdcard / FbImages /



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



所以这里是我的问题如何打开sdcard文件夹以及如何从多个图像中选择单个图像

解决方案

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



尝试以下代码选择图片

  btnSelect.setOnClickListener OnClickListener(){

@Override
public void onClick(View v){
// TODO自动生成的方法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 = 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); 


I am allowing user to post a message on their [Friend & User] Wall along with single static image, and for that image i am using Web Image URL

But now i wish to allow user to choose any single image from multiple images, like 10 images stored in a particular folder in SDCard, and then post to Wall.

So here is my question, how to do that?

My existing code to post static image on Wall, read below:

@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";

Check existing screen of my app,

As you can see in above screen i am showing only single static image as i have written above, but now i wanna allow user to choose an image from multiple images using SD Card, my SDCard path like: /sdcard/FbImages/

now i want to know how to place button in above screen [because i am not using any custom xml for this, that's native feature in FacebookSDK]

So here is my question how to open sdcard folder and how to choose single image to post from multiple images

解决方案

you have to find path for that image.

try following code to select image

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);
        }
    });

get path for selectd image

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);
}

then use

  params.putString("picture",selectedImagePath);

这篇关于如何让用户使用SDCard文件夹在墙上发布图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆