我有一个问题:我有一个函数,使我从库中的形象;但是当我选择的形象,我不明白这一点。
。 公共无效funzione(视图v){
INT SELECT_IMAGE = 1;
意向意图=新的意图();
intent.setType(图像/ *);
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(意向,选择图片),SELECT_IMAGE);
我要通过电子邮件发送这个形象,但我现在不如何实现这一点:
意向书我=新意图();
i.setType(应用程序/八位字节流);
i.setAction(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL,新的String [] {prova@libero.it});
i.putExtra(android.content.Intent.EXTRA_SUBJECT,测试SUBJ);
i.putExtra(android.content.Intent.EXTRA_TEXT,CORPO邮件测试);
startActivity(Intent.createChooser(我,发送电子邮件));
}
解决方案
刚过类声明顶部声明全局变量:
私有静态诠释RESULT_LOAD_IMAGE = 1;
私有静态最终诠释PICK_FROM_GALLERY = 2;
位图的缩略图= NULL;
调用这样的意向:(您funizone()函数)
公共无效funzione(){
意图=新的意图(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(在,RESULT_LOAD_IMAGE);
}
处理结果是这样的:在类的任何位置声明你的onCreate此之外
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,因此code,数据);
如果(要求code == RESULT_LOAD_IMAGE和放大器;&安培;结果code == RESULT_OK和放大器;&安培;!NULL =数据){
乌里selectedImage = data.getData();
的String [] filePathColumn = {MediaStore.Images.Media.DATA};
光标光标= getContentResolver()查询(selectedImage,filePathColumn,NULL,NULL,NULL);
cursor.moveToFirst();
INT参数:columnIndex = cursor.getColumnIndex(filePathColumn [0]);
字符串picturePath = cursor.getString(参数:columnIndex);
cursor.close();
缩略图=(BitmapFactory.de codeFILE(picturePath));
缩略图是你的照片了,现在用它玩!
I have a problem: I have a function that brings me the image from the gallery ;but when I select the image, I don't get it.
public void funzione(View v){
int SELECT_IMAGE=1;
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"),SELECT_IMAGE);
I have to email this image, but I don't now how to implement this:
Intent i = new Intent();
i.setType("application/octet-stream");
i.setAction(Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{ "prova@libero.it" });
i.putExtra(android.content.Intent.EXTRA_SUBJECT, "Test subj");
i.putExtra(android.content.Intent.EXTRA_TEXT, "corpo mail test");
startActivity(Intent.createChooser(i, "Send email"));
}
解决方案
Declare Global Variables just after your class declaration at the top:
private static int RESULT_LOAD_IMAGE = 1;
private static final int PICK_FROM_GALLERY = 2;
Bitmap thumbnail = null;
Call the intent like this: (Your funizone() function)
public void funzione(){
Intent in = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(in, RESULT_LOAD_IMAGE);
}
Handle the result like this: Declare this outside of your onCreate anywhere in the class.
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data){
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
thumbnail = (BitmapFactory.decodeFile(picturePath));
thumbnail is your picture, now play with it!