如何从Android中的对话框触发隐式意图

  • 本文关键字:意图 对话框 Android android
  • 更新时间 :
  • 英文 :


我正在使用共享对话框选择要在本地数据库中上传的映像,但是我无法启动活动以捕获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);
        }
    });

尝试使用 setType() 添加类型为"图像",因为您想选择image,

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

,还检查点击侦听器是否在工作。

最新更新