我想从特定路径显示文件,我将在RecyclerView中实现它。但是我不知道如何显示该文件。
这是我的MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_add = findViewById(R.id.btn_add);
tv_filePath = findViewById(R.id.tv_filePath);
btn_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(intent, 10);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 10:
if (resultCode == RESULT_OK) {
String path = data.getData().getPath();
tv_filePath.setText(path);
uri = Uri.fromFile(new File(path));
toDisplay = new File(uri.getPath());
}
break;
}
}
我已经有了文件路径,如何从文件路径显示该文件?