Android从DialogFragment调用图像选择器

时间:2013-07-07 12:56:35

标签: android layout browser dialog image

我有DialogFragment类,我有一个按钮,可以用Image Browser打开新活动,

按钮代码:

Intent intent = new Intent( getActivity(), BrowsePicture.class );
                    intent.setType( "image/*" );
                    intent.setAction( Intent.ACTION_GET_CONTENT );
                    startActivityForResult( Intent.createChooser( intent, "Choose image" ), 1 );

这里是BrowsePicture.class:

public class BrowsePicture extends Activity {

private static final int SELECT_PICTURE = 1;

private String selectedImagePath;
private String filemanagerstring;
public static String IMAGE_NAME;

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == SELECT_PICTURE) {
            Uri selectedImageUri = data.getData();
            Log.d("URI VAL", "selectedImageUri = " + selectedImageUri.toString());
            selectedImagePath = getPath(selectedImageUri);

            if(selectedImagePath!=null){         
                // IF LOCAL IMAGE, NO MATTER IF ITS DIRECTLY FROM GALLERY (EXCEPT PICASSA ALBUM),
                // OR OI/ASTRO FILE MANAGER. EVEN DROPBOX IS SUPPORTED BY THIS BECAUSE DROPBOX DOWNLOAD THE IMAGE 
                // IN THIS FORM - file:///storage/emulated/0/Android/data/com.dropbox.android/...
                System.out.println("local image"); 
            }
            else{
                System.out.println("picasa image!");
                loadPicasaImageFromGallery(selectedImageUri);
            }
        }
    }
}

但是当我点击对话框中的按钮时,我可以看到图像浏览器,但我不能正常工作,我觉得有些问题:  startActivityForResult(Intent.createChooser(intent,“Choose image”),1);

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试像这样 getActivity().startActivityForResult( Intent.createChooser( intent, "Choose image" ), 1 );