0

私はこのトピックで研究開発を行っています。

ギャラリーから画像を取得していて、画像ビューで表示できます。

そして、その画像ビューを長押しすると、共有できます。

しかし、問題は、添付された画像が出力として取得されないことです。

 public class Facebookhome extends Activity {

Button share;

ImageView img;

Uri screenshotUri;

private static final int SELECT_PICTURE = 1;

private String selectedImagePath;

@Override

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_facebookhome);

    share = (Button) findViewById(R.id.button1);

    img = (ImageView) findViewById(R.id.imageView1);

    share.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            Intent intent = new Intent();

            intent.setType("image/*");

            intent.setAction(Intent.ACTION_GET_CONTENT);

            startActivityForResult(

                    Intent.createChooser(intent, "Select 

 Picture"),

                    SELECT_PICTURE);

        }

    });


    img.setOnLongClickListener(new View.OnLongClickListener() {

        public boolean onLongClick(View v) {

            shareimage();

            return true;

        }

    });

}

public void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (resultCode == RESULT_OK) {

        if (requestCode == SELECT_PICTURE) {

            Uri selectedImageUri = data.getData();

            selectedImagePath = getPath(selectedImageUri);

            System.out.println("Image Path : " + selectedImagePath);

            img.setImageURI(selectedImageUri);

        }

    }

}

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

}

public void shareitem() {

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);

    sharingIntent.setType("text/plain");

    String shareBody = "Here is the share content body";

    sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,

            "Subject Here");

    sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);

    startActivity(Intent.createChooser(sharingIntent, "Share via"));

}

public void shareimage() {

    Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);

    screenshotUri = Uri.parse(selectedImagePath);

    sharingIntent.setType("image/jpg");

    sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM,

            screenshotUri);

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

    // Toast.makeText(getBaseContext(), "FB Last",

    // Toast.LENGTH_LONG).show();

}
}
4

1 に答える 1

0
private static int RESULT_LOAD_IMAGE = 1;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button buttonLoadImage = (Button) findViewById(R.id.buttonLoadPicture);
    buttonLoadImage.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            Intent i = new Intent(
                    Intent.ACTION_PICK,
                    android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);

            startActivityForResult(i, RESULT_LOAD_IMAGE);
        }
    });
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
        Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };

        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String picturePath = cursor.getString(columnIndex);
       Uri screenshotUri = Uri.parse(picturePath);
        cursor.close();

        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("image/jpg"");
        i.putExtra(Intent.EXTRA_EMAIL,
                new String[] { "aa@gmail.com" });
        i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
        i.putExtra(Intent.EXTRA_STREAM, screenshotUri);
        startActivity(Intent.createChooser(i, "Send mail..."));


    }


}
于 2013-03-19T09:36:03.853 に答える