0

我正在开发一个应用程序,它允许用户将图片附加到应用程序本身的某些文本上,但用户需要访问手机图库才能将照片从中提取并放入应用程序。我的手机运行的是 2.3.5 这个版本可以吗??网上好像找不到确切的答案!!多谢你们.....

4

2 回答 2

0

它绝对能够从图库中检索图像。您可以发布您的代码,您如何尝试从图库中获取图像?

于 2012-05-25T10:24:29.030 回答
0

要从图库中选择图像,

public class SelectPhotoActivity extends Activity {

private static final int SELECT_PICTURE = 1;
private String selectedImagePath="";

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    intent.addCategory(Intent.CATEGORY_OPENABLE);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    startActivityForResult(intent, SELECT_PICTURE); 
}

public String getPath(Uri uri) {
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor
            .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE)
        {
            Uri selectedImageUri = data.getData();
            selectedImagePath = getPath(selectedImageUri);
           // here you can set the image
            }
    }
}

}
于 2012-05-25T11:32:43.900 回答