如何从使用ImageView功能的阵列共享图像? [英] How can I share images from an Array that uses ImageView feature?
本文介绍了如何从使用ImageView功能的阵列共享图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有疑问。
如何从使用ImageView功能的数组共享图像?
How can I share images from an Array that uses ImageView feature?
我的数组有超过100张图片,例如:
My array has more than 100 images, an example:
Final int [] photos = {
R.drawable.abrir_a_boca,
R.drawable.rooms,
R.drawable.firmly,
R.drawable.agradeca,
R.drawable.alfaiate,
R.drawable.ancora,
}
要分享我正在尝试使用Intent.ACTION_SEND
To share I'm trying to use Intent.ACTION_SEND
Set.setOnClickListener (new View.OnClickListener () {
@Override
Public void onClick (View v)
{
Intent sharingIntent = new Intent (Intent.ACTION_SEND);
Uri screenshotUri = Uri.parse (photos???);
SharingIntent.setType ("image / *");
SharingIntent.putExtra (Intent.EXTRA_STREAM, screenshotUri);
StartActivity (Intent.createChooser (sharingIntent, "Share image using"));
}
});
我如何分享图像?
非常感谢你!!!
推荐答案
在分享你的形象之前你必须做一些操作,所以在你的 Manifest.xml
:
You have to do some operations before you share your image, so add the permission in your Manifest.xml
:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
拳头,从你的创建位图
对象可绘制资源:
Fist, create a Bitmap
object from your drawable resource:
Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.xxxx);
然后,获取您分享图片的路径
Then, get the path for you share your image
String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+"/yourImage.jpg";
OutputStream out = null;
File file=new File(path);
try {
out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
path=file.getPath();
Uri uri = Uri.parse("file://"+path);
最后,创建你的意图:
Intent intent = new Intent();
intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/jpg");
startActivity(Intent.createChooser(intent,"Share with..."));
这篇关于如何从使用ImageView功能的阵列共享图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文