我正在开发一个应用程序,在此活动中按下一个按钮,可以选择上传任何文件.

文件选择器正确加载,但所有图像都是不可选择的(灰色).我将READ_EXTERNAL_STORAGE权限添加到Manifest文件,但我不知道为什么它仍然不允许我选择文件.这是我正在使用的代码

private Button uploadButton;

private TextView uploadFile;

private static final int PICKFILE_RESULT_CODE = 1;

private String selectedImagePath;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

uploadButton = (Button)findViewById(R.id.upload_button);

uploadFile = (TextView)findViewById(R.id.uploadFile);

uploadButton.setOnClickListener(new View.OnClickListener()

{

public void onClick(View v){

Intent intent = new Intent(Intent.ACTION_GET_CONTENT);

intent.setType("file/*");

startActivityForResult(intent,PICKFILE_RESULT_CODE);

}});

}

@Override

protected void onActivityResult(int requestCode,int resultCode,Intent data) {

switch(requestCode){

case PICKFILE_RESULT_CODE:

if (resultCode==RESULT_OK){

String FilePath = data.getData().getPath();

uploadFile.setText(FilePath);

}

break;

}

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐