0

我正在一个应用程序中工作,我可以将我的画廊图像分享到 facebook、twitter

我已经搜索了一些链接..每个人都提到了意图服务..但我不知道它将如何在我的应用程序中使用,如果有人帮助我提供完整的代码,我将非常感激

            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("image/jpeg");

            share.putExtra(Intent.EXTRA_STREAM,
              Uri.parse("file:///sdcard/DCIM/Camera/myPic.jpg"));

            startActivity(Intent.createChooser(share, "Share Image"));
4

1 回答 1

2

试试这个代码:

    Button button = (Button)findViewById(R.id.facebookButton);

    button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
                    String path = "path to the image";
                    Uri imageUri = Uri.parse(path);

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

                     startActivity(Intent.createChooser(sharingIntent , "Send image using.."));

        }
    });
于 2013-02-08T15:30:49.357 回答