张贴在朋友的挂画? [英] Posting picture on a friend's wall?

查看:172
本文介绍了张贴在朋友的挂画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以张贴在一个朋友的墙上的一幅画?
我使用这个code:

Is it possible to post a picture in a friend's wall? I'm using this code :

Bundle postdata = new Bundle();
postdata.putString("message", msg);
postdata.putByteArray("picture", pic);
// this code, i found it in another questions but it doesn't
// seem to help much:
postdata.putString("target_id", usr);
// then i  use the Asynchronous request.
mAsyncRunner.request(usr+"/feed", postdata, "POST",new WallRequestListener(), null);

其中,图片是图片为ByteArray和 USR 是朋友的ID。
它只是显示了朋友的墙上的消息,但根本没有图片。

where pic is the picture as a byteArray and usr is the friend's ID. It just shows the message on the friend's wall but no picture at all.

推荐答案

这是我在我的应用程序使用。和它的作品。

This is what I use in my app. And it works.

protected void uploadPhoto() {
    if (!Utility.mFacebook.isSessionValid()) {
        Util.showAlert(this, "Warning", "You must first log in.");
    } else {
        if (targetUri != null) {
            Bundle params = new Bundle();
            try {
                params.putByteArray("photo", Utility.scaleImage(getApplicationContext(), targetUri));
            } catch (Exception e) {
                e.printStackTrace();
            }
            params.putString("caption", txtPhotoCaption.getText().toString());
            Utility.mAsyncRunner.request( "replace this with the users ID"+ "/photos&access_token=" + Utility.mFacebook.getAccessToken(), 
                    params, "POST", new PhotoUploadListener(), null);
            txtPhotoCaption.setText("");
            Toast.makeText(getApplicationContext(), "Photo uploaded successfully", Toast.LENGTH_SHORT).show();
            this.finish();
        }
    }
}

请注意,我用同样的方法作为示例应用程序使用。没有进入的利弊或缩放或不缩放图像的利弊。在标题属性正在从一个EditText拉动。和实际图像是在该领域 targetUri ,它被声明为全局变量。它获取使用设备上的默认画廊的形象。为了完整起见,这是code抓住从默认图库应用程序的形象。 (此提示用户选择应用程序)

Please note, that I am using the same method as used in the sample app. Without getting into the pros or cons of scaling or not scaling the image. The "caption" attribute is being pulled from an EditText. And the actual image is in the field "targetUri", which is declared as a global variable. It's fetching the image using the default Gallery on the device. For the sake of completeness, this is the code to grab the image from the default Gallery app. (this prompts the user to select the app)

btnAddPhoto.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                startActivityForResult(intent, 0);
            }
        });

和它在处理的onActivityResult()这里:

注意我还设置选择图像中的ImageView为preVIEW到登录的用户

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        // TODO Auto-generated method stub
        super.onActivityResult(requestCode, resultCode, data);

        Bitmap bitmap = null;
        if (resultCode == RESULT_OK)    {
            targetUri = data.getData();
            Log.e("IMG URI", targetUri.toString());
            try {
                bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
                try {
                    Utility.scaleImage(getApplicationContext(), targetUri);
                    imgDisplaySelectedImage.setImageBitmap(bitmap);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
    }

我已经再次测试上传到朋友墙之前,我在这里张贴的code作为一个答案。而且它确实有效。希望这可以帮助你。

I have again tested an upload to a friends wall before I posted the code here as an answer. And it really works. Hope this helps you as well.

编辑:

在最新的评论中提到,使用Intent.ACTION_GET_CONTENT没打的的onActivityResult下的preVIEW图像显示漂亮的()。修改code一点点的工作。

As mentioned in the latest comment, using Intent.ACTION_GET_CONTENT did not play nice with the preview image display under the onActivityResult(). Modifying the code a little worked.

我觉得奇怪的是,在完成动作使用弹出,我没有得到的Astro文件管理器也不给我文件管理器在我的Galaxy S的画廊是事实(关闭市场,而不是股票)和Quickoffice Pro中。话虽这么说,选择从两个仍然工作和照片上传静止。

What I find strange is the fact that in the "Complete action using" popup, I did not get the Astro File Manager nor the Gallery on my Galaxy S. It gives me File Manager (off the market, not the stock) and Quickoffice Pro. That being said, selections from either the two still works and photos still upload.

这篇关于张贴在朋友的挂画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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