如何使用“共享圖像使用”共享意圖共享圖像在Android?我有圖像廚房的應(yīng)用程序,我把所有的圖像放在繪圖-hdpi文件夾。在我的活動(dòng)中,我把圖像叫做:private Integer[] imageIDs = {
R.drawable.wall1, R.drawable.wall2,
R.drawable.wall3, R.drawable.wall4,
R.drawable.wall5, R.drawable.wall6,
R.drawable.wall7, R.drawable.wall8,
R.drawable.wall9, R.drawable.wall10};因此,現(xiàn)在我想知道如何使用共享意圖共享這些圖像,我提供了這樣的共享代碼: Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + imageIDs);
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});我也有分享按鈕,當(dāng)我點(diǎn)擊共享按鈕共享框打開(kāi),但當(dāng)我剪裁任何服務(wù),大部分是它的崩潰或一些服務(wù)說(shuō):無(wú)法打開(kāi)圖像,所以我如何能夠修復(fù)這個(gè),或者有任何格式代碼來(lái)共享圖像?編輯:我試過(guò)使用下面的代碼。但這不起作用。Button shareButton = (Button) findViewById(R.id.share_button);
shareButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse("android.resource://com.android.test/*");
try {
InputStream stream = getContentResolver().openInputStream(screenshotUri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
sharingIntent.setType("image/jpeg");
sharingIntent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
startActivity(Intent.createChooser(sharingIntent, "Share image using"));
}
});如果不介意的話,請(qǐng)更正我上面的代碼,或者給我一個(gè)適當(dāng)?shù)氖纠齪lz,我如何共享可繪制-hdpi文件夾中的圖像?
3 回答

RISEBY
TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊
Bitmap icon = mBitmap;Intent share = new Intent(Intent.ACTION_SEND);share.setType("image/jpeg");ByteArrayOutputStream bytes = new ByteArrayOutputStream();icon.compress(Bitmap.CompressFormat.JPEG, 100, bytes);File f = new File(Environment.getExternalStorageDirectory() + File.separator + "temporary_file.jpg");try { f.createNewFile(); FileOutputStream fo = new FileOutputStream(f); fo.write(bytes.toByteArray());} catch (IOException e) { e.printStackTrace();}share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/temporary_file.jpg"));startActivity(Intent.createChooser(share, "Share Image"));
- 3 回答
- 0 關(guān)注
- 430 瀏覽
添加回答
舉報(bào)
0/150
提交
取消