我的ImageAdapter
课程:
public Integer[] mThumbIds = {
R.drawable.p_1,
R.drawable.p_2,
R.drawable.p_3,
R.drawable.p_4,
R.drawable.p_5
};
我的ShareItemMenu
课程:
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
MenuItem shareitem= (MenuItem)menu.findItem(R.id.action_share);
ShareActionProvider provider = (ShareActionProvider)shareitem.getActionProvider();
Bitmap bitmap;
OutputStream output;
bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.v);
File filepath = Environment.getExternalStorageDirectory();
File dir = new File(filepath.getAbsolutePath() + "/Share Image Tutorial/");
dir.mkdirs();
File file = new File(dir, "v.png");
try {
Intent share = new Intent(Intent.ACTION_SEND);
share.setAction(Intent.ACTION_SEND);
share.setType("image/jpeg");
output = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.PNG, 100, output);
output.flush();
output.close();
Uri uri = Uri.fromFile(file);
share.putExtra(Intent.EXTRA_STREAM, uri);
provider.setShareIntent(share);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
以上代码仅共享1张v.png
图片。我有一系列图像,我想分享用户选择图像。
请建议我如何在File file = new File(dir, "v.png");