1

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,

enter image description here

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

Sun
  • 6,768
  • 25
  • 76
  • 131
  • Please check my answer below. The screen Shot which you have upload its of the app Request. So, can only able to change it if other all images have their own url. – Shreyash Mahajan Sep 09 '13 at 06:01

3 Answers3

1

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);
Ketan Ahir
  • 6,678
  • 1
  • 23
  • 45
  • bro please come here, i need support – Sun Sep 07 '13 at 06:17
  • hi actually i am not getting how to use your code in mine, i have also uploaded screen shot of my app, now i want to know how to place button in above screen to open sdcard folder and how to choose one to post from multiple images – Sun Sep 07 '13 at 06:25
  • just put button anywhere in your activity and select image(get path) by onclick() before displaying facebook dialog. – Ketan Ahir Sep 07 '13 at 06:47
  • where you want to do facebook stuff. – Ketan Ahir Sep 07 '13 at 07:17
0

Thanks for notifying me to the answer here. As you have seen here, I am sending app request to my Facebook friend. However its nothing like to post photo on Friend's wall. There you only able to post App icon with the url ASK.

If you want to post photo on Friends wall with message then please check my below answer.

Bundle param = new Bundle();
param.putString("message", "picture caption");
param.putByteArray("picture", ImageBytes);
mAsyncRunner.request("me/photos", param, "POST", new SampleUploadListener());

In my above code, ImageBytes is the byte[] of the Image. You will have to play little to select image from the particular folder then convert that selected image in to byte[]. Use that byte[] in my above code.

halfer
  • 19,824
  • 17
  • 99
  • 186
Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188
  • thanks for help, but i not getting how to allow user to pick a single image from multiple in my screen, that's the main question – Sun Sep 09 '13 at 06:10
  • Do you want to have images from gallery then check this: http://stackoverflow.com/questions/2507898/how-to-pick-an-image-from-gallery-sd-card-for-my-app-in-android – Shreyash Mahajan Sep 09 '13 at 06:31
0

Use it when pick bitmap from sdcard and give the path also past this code.

protected void share(String nameApp, String imagePath, String text) {
        // TODO Auto-generated method stub

        try {
            List<Intent> targetedShareIntents = new ArrayList<Intent>();
            Intent share = new Intent(android.content.Intent.ACTION_SEND);
            share.setType("image/jpeg");
            List<ResolveInfo> resInfo = getPackageManager()
                    .queryIntentActivities(share, 0);
            if (!resInfo.isEmpty()) {
                for (ResolveInfo info : resInfo) {
                    Intent targetedShare = new Intent(
                            android.content.Intent.ACTION_SEND);
                    targetedShare.setType("image/jpeg"); // put here your mime
                    // type
                    if (info.activityInfo.packageName.toLowerCase().contains(
                            nameApp)
                            || info.activityInfo.name.toLowerCase().contains(
                                    nameApp)) {
                        targetedShare.putExtra(Intent.EXTRA_SUBJECT, text);
                        targetedShare.putExtra(Intent.EXTRA_TEXT, text);
                        targetedShare.putExtra(Intent.EXTRA_STREAM,
                                Uri.fromFile(new File(imagePath)));
                        targetedShare.setPackage(info.activityInfo.packageName);
                        targetedShareIntents.add(targetedShare);
                    }
                }
                Intent chooserIntent = Intent.createChooser(
                        targetedShareIntents.remove(0), "Select app to share");
                chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS,
                        targetedShareIntents.toArray(new Parcelable[] {}));
                startActivity(chooserIntent);
            }
        } catch (Exception e) {
        }

    }
halfer
  • 19,824
  • 17
  • 99
  • 186
Jelly Bean
  • 137
  • 10