问题描述
我在该应用程序,我把所有的图像转换成可提拉 - 华电国际文件夹中的图像厨房的应用程序。我所谓的图像在我的活动是这样的:
私人整数[] 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
};
所以,现在我想知道如何使用共享意向我的推杆共享code这样我分享这个图片:
按钮shareButton =(按钮)findViewById(R.id.share_button);
shareButton.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
意图sharingIntent =新的意图(Intent.ACTION_SEND);
乌里screenshotUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI +/+ imageIDs);
sharingIntent.setType(为image / jpeg);
sharingIntent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
startActivity(Intent.createChooser(sharingIntent,分享图像使用));
}
});
和我有分享按钮还当我点击共享按钮共享盒打开但是,当我cliked任何服务主要是它的崩溃或者一些服务说:无法打开图片所以,我怎么能解决这个问题,或有任何othere格式code共享图像????
编辑:
我试着用下面的code。但它不工作。
按钮shareButton =(按钮)findViewById(R.id.share_button);
shareButton.setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
意图sharingIntent =新的意图(Intent.ACTION_SEND);
乌里screenshotUri = Uri.parse(android.resource://com.android.test/*);
尝试 {
InputStream的流= getContentResolver()openInputStream(screenshotUri)。
}赶上(FileNotFoundException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
sharingIntent.setType(为image / jpeg);
sharingIntent.putExtra(Intent.EXTRA_STREAM,screenshotUri);
startActivity(Intent.createChooser(sharingIntent,分享图像使用));
}
});
如果不介意有人PLZ纠正我的上述code或给我一个适当的例子PLZ如何从绘制,华电国际文件夹
分享我的图片 位图图标= mBitmap;
意图份额=新的意图(Intent.ACTION_SEND);
share.setType(为image / jpeg);
ByteArrayOutputStream字节=新ByteArrayOutputStream();
icon.com preSS(Bitmap.Com pressFormat.JPEG,100个字节);
文件F =新的文件(Environment.getExternalStorageDirectory()+文件分割符+temporary_file.jpg);
尝试 {
f.createNewFile();
FileOutputStream中FO =新的FileOutputStream(F);
fo.write(bytes.toByteArray());
}赶上(IOException异常E){
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM,Uri.parse(文件:///sdcard/temporary_file.jpg));
startActivity(Intent.createChooser(份额,共享图片));
I have image galley app in that app I placed all the images into the drawable-hdpi folder.and i called images in my activity like this :
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
};
So now i want know how do i share this images using sharing Intent i putted sharing code like this :
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"));
}
});
And i have sharing button also when i click on share button Sharing box is openingBut when i cliked any service mostly its crashing or some services say : unable to open imageSo how i can fix this or is there any othere format code to share images ????
Edit :
I tried using the code below. But its not working.
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"));
}
});
If don't mind somebody plz correct my above code OR give me a proper example plz How do i Share my images from drawable-hdpi folder
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"));
这篇关于如何使用"分享图像使用"分享意图在android的共享图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!