public void share_image_text_GPLUS() {
File pictureFile;
try {
File rootSdDirectory = Environment.getExternalStorageDirectory();
pictureFile = new File(rootSdDirectory, "attachment.jpg");
if (pictureFile.exists()) {
pictureFile.delete();
}
pictureFile.createNewFile();
FileOutputStream fos = new FileOutputStream(pictureFile);
URL url = new URL("http://img.youtube.com/vi/AxeOPU6n1_M/0.jpg");
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.connect();
InputStream in = connection.getInputStream();
byte[] buffer = new byte[1024];
int size = 0;
while ((size = in.read(buffer)) > 0) {
fos.write(buffer, 0, size);
}
fos.close();
} catch (Exception e) {
System.out.print(e);
// e.printStackTrace();
return;
}
Uri pictureUri = Uri.fromFile(pictureFile);
Intent shareIntent = ShareCompat.IntentBuilder.from(this)
.setText("Hello from Google+!").setType("image/jpeg")
.setStream(pictureUri).getIntent()
.setPackage("com.google.android.apps.plus");
startActivity(shareIntent);
}
buttonLoadImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
share_image_text_GPLUS();
}
});
https://developers.google.com/+/mobile/android/share/#adding_basic_sharing請參考這個 –