如何在windows平台上显示android文件浏览器
我想在windows平台上的android中显示文件列表。 我用了这个方法:
private void browseToRoot() {
browseTo(new File("C:\\");
}
private void browseTo(final File aDirectory){
if (aDirectory.isDirectory()){
this.currentDirectory = aDirectory;
fill(aDirectory.listFiles());
}else{
OnClickListener okButtonListener = new OnClickListener(){
// @Override
public void onClick(DialogInterface arg0, int arg1) {
// Lets start an intent to View the file, that was clicked...
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("file://" + aDirectory.getAbsolutePath()));
startActivity(myIntent);
}
};
OnClickListener cancelButtonListener = new OnClickListener(){
// @Override
public void onClick(DialogInterface arg0, int arg1) {
// Do nothing
}
};
new AlertDialog.Builder(this)
.setTitle("Question")
.setMessage("Do you want to open that file?"+ aDirectory.getName())
.setPositiveButton("OK", okButtonListener)
.setNegativeButton("Cancel", cancelButtonListener)
.show();
}
}
但是不行。如果我更改为“BrowseTo(new File("/"))”,它就可以工作。
谢谢你的帮助
I want to show file list in android in windows platform.
I used the method :
private void browseToRoot() {
browseTo(new File("C:\\");
}
private void browseTo(final File aDirectory){
if (aDirectory.isDirectory()){
this.currentDirectory = aDirectory;
fill(aDirectory.listFiles());
}else{
OnClickListener okButtonListener = new OnClickListener(){
// @Override
public void onClick(DialogInterface arg0, int arg1) {
// Lets start an intent to View the file, that was clicked...
Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("file://" + aDirectory.getAbsolutePath()));
startActivity(myIntent);
}
};
OnClickListener cancelButtonListener = new OnClickListener(){
// @Override
public void onClick(DialogInterface arg0, int arg1) {
// Do nothing
}
};
new AlertDialog.Builder(this)
.setTitle("Question")
.setMessage("Do you want to open that file?"+ aDirectory.getName())
.setPositiveButton("OK", okButtonListener)
.setNegativeButton("Cancel", cancelButtonListener)
.show();
}
}
But It doesn't work . If I change to "BrowseTo(new File("/"))" ,it work.
thanks for help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 是一个基于 Linux 的操作系统。
您应该使用 Linux 风格的文件路径
Android is a Linux-based OS.
You should use Linux-style paths to files
尝试使用
Environment.getRootDirectory()
而不是“/”谢谢
迪帕克
Try with
Environment.getRootDirectory()
instead of "/"Thanks
Deepak