我有一个问题:我有一个功能,可以从画廊中获取图像;但是当我选择图像时,我没有得到它.
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);
Run Code Online (Sandbox Code Playgroud)
我必须通过电子邮件发送此图片,但我现在不知道如何实现这个:
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"));
}
Run Code Online (Sandbox Code Playgroud)
Sky*_*net 12
在您的顶级类声明之后声明全局变量:
private static int RESULT_LOAD_IMAGE = 1;
private static final int PICK_FROM_GALLERY = 2;
Bitmap thumbnail = null;
Run Code Online (Sandbox Code Playgroud)
像这样调用这个意图:(你的funizone()函数)
public void funzione(){
Intent in = new Intent(Intent.ACTION_PICK,android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(in, RESULT_LOAD_IMAGE);
}
Run Code Online (Sandbox Code Playgroud)
像这样处理结果:在类中的任何地方声明你的onCreate之外.
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));
Run Code Online (Sandbox Code Playgroud)
缩略图是你的照片,现在玩它!
| 归档时间: |
|
| 查看次数: |
13107 次 |
| 最近记录: |