I am developing an application, and in this exercise a button is clicked and any file can be selected for download. File selection loads correctly, but all images are not selectable (grayed out). I added READ_EXTERNAL_STORAGE permission to the manifest file, but I have no idea why it still will not let me select the file. Here is the code I'm using
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; } }
source share