通过android中的意图分享照片到Facebook

时间:2012-12-17 07:25:19

标签: android facebook

我想通过特定网址的意图将照片分享到脸书。

http://tineye.com/images/widgets/mona.jpg

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("http://tineye.com/images/widgets/mona.jpg");
sharingIntent.setType("image/png");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));

来自galllery它的工作正常。

但是当我通过上面的网址将意图照片不在Facebook上分享时。

帮助我......

2 个答案:

答案 0 :(得分:0)

从网址发布图片,您将执行以下步骤:

第1步:从网址获取位图:

看这篇文章

How to load an ImageView by URL in Android?

从URL

获取图像位图

第2步:

暂时在Images.Media中存储位图,发送后可将其删除

String path = Images.Media.insertImage(getContentResolver(), 
                            bitmapiamge, "title", null);
Uri screenshotUri = Uri.parse(path);

Intent sharingIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
emailIntent.setType("image/png");

startActivity(Intent.createChooser(emailIntent, "Send email using"));

并将位图发送到Facebook墙看到这篇文章:

Android: Intent.ACTION_SEND with EXTRA_STREAM doesn't attach any image when choosing Gmail app on htc Hero

答案 1 :(得分:-1)

将背景图像设置为从一个活动到另一个活动的相对布局的代码

第一个活动中的

见下面的代码

protected void onActivityResult(int requestCode, int resultCode, Intent data) 
 {
    // TODO Auto-generated method stub
    if(requestCode == 1011)
    {
        if(resultCode == RESULT_OK)
        {
            image.setImageURI(data.getData());
            imageUri = data.getData();

            String filePath[] = {MediaStore.Images.Media.DATA}; //A column name which to be return
            Cursor c = getContentResolver().query(imageUri, filePath, null, null, null);
            c.moveToFirst();
            int index = c.getColumnIndex(filePath[0]);
            String path = c.getString(index);//actual path of file in sa card
            c.close();

            if(path!=null)
            {
                //Bitmap bmp =BitmapFactory.decodeFile(path);
                SharedPreferences.Editor editor = pref.edit();              
                editor.putString("image",path);//set the path of file into the SharedResources
                editor.commit();
            }
        }

    }   
}

设置背景图片的代码

 void setLayoutBackground()
{
    SharedPreferences pref = getSharedPreferences("style_pref", 0);
    String path = pref.getString("image",null);
    Bitmap myBitmap = BitmapFactory.decodeFile(path);
        BitmapDrawable d = new BitmapDrawable(getResources(),myBitmap);
        layout.setBackgroundDrawable(d);
}