首页 > 解决方案 > 如何从android中的Dialog触发隐式意图?

问题描述

我正在使用共享对话框来选择要在本地数据库中上传的图像,但是我无法启动活动以获取捕获 URI 链接的结果。

代码如下:

selectImage = (Button) dialog.findViewById(R.id.selectImage);

selectImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //code to fethc the image form the local strorage
            Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI );
            startActivityForResult(i, REQUEST_CODE);
        }
    });

标签: android

解决方案


尝试将类型添加为“图像”, setType() 因为您要选择图像,

Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI );    
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"), req_code);

并检查点击监听器是否正常工作。


推荐阅读