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



我想通过特定网址的意图将照片分享到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"));

从画廊它的工作很好。

但是当我将上面的网址传递给意图照片而不是在Facebook上分享时。

帮我这个...

要从Web URL发布图像,您将执行以下步骤:

第 1 步:从 URL 获取位图:

看这篇文章

如何在Android中通过URL加载ImageView?

用于从 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:在htc Hero上选择Gmail应用程序时,带有EXTRA_STREAM Intent.ACTION_SEND不会附加任何图像

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

在第一个活动中,请参阅如下所示的代码

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

最新更新