我正在做这个主题的研发。
我从图库中获取图像并能够在图像视图中查看。
通过长按该图像视图,我可以分享。
但问题是我没有将附加图像作为输出..
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();
}
}