如何在staorage access framework的文件资源管理器中显示Toast,以便让用户知道应用程序正在读取文件,这可能需要几秒钟的时间。
public void openFile() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("text/plain");
startActivityForResult(intent, OPEN_REQUEST_CODE);
}
我试着用这个方法添加Toast,但没有起作用。
private String readFileContent(Uri uri) throws IOException {
InputStream inputStream =
getContentResolver().openInputStream(uri);
BufferedReader reader =
new BufferedReader(new InputStreamReader(
inputStream));
StringBuilder stringBuilder = new StringBuilder();
String currentline;
while ((currentline = reader.readLine()) != null) {
stringBuilder.append(currentline + "\n");
}
inputStream.close();
return stringBuilder.toString();
}
发布于 2018-09-20 06:31:38
当用户等待时,Toast不是一个好主意。在您的应用程序读取文件时创建一个ProgressDialog,并在文件读取完成后将其清除。
https://stackoverflow.com/questions/52414986
复制相似问题