【问题标题】:How to Move to a folder in the external SD card, by specifying the folder path in Android如何通过在Android中指定文件夹路径移动到外部SD卡中的文件夹
【发布时间】:2011-06-18 07:15:56
【问题描述】:

请帮忙,当通过指定文件夹的完整路径单击按钮时,如何显示指定文件夹的内容。我尝试如下,但我的应用程序崩溃了。

Button buttonFom = (Button) findViewById(R.id.fom);
    buttonFom.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            getDir("/mnt/sdcard/external_sd/DOC1/HW 850Xp/");
        }
    });


private void getDir(String dirPath) {
    myPath.setText("Location: " + dirPath);

    item = new ArrayList<String>();
    path = new ArrayList<String>();

    File f = new File(dirPath);
    File[] files = f.listFiles();

    if (!dirPath.equals(root)) {

        item.add(root);
        path.add(root);

        item.add("../");
        path.add(f.getParent());

    }

    for (int i = 0; i < files.length; i++) {
        File file = files[i];
        path.add(file.getPath());
        if (file.isDirectory())
            item.add(file.getName() + "/");
        else
            item.add(file.getName());
    }

    ArrayAdapter<String> fileList = new ArrayAdapter<String>(this,
            R.layout.row, item);
    setListAdapter(fileList);
}

【问题讨论】:

    标签: android android-listview android-intent android-sdcard


    【解决方案1】:

    首先您需要在 Android Manifest 文件中设置用户权限以对 SD 卡进行写访问

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    没有它,您将无法访问 SD 卡

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2011-08-06
      • 2015-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      • 2012-01-27
      • 1970-01-01
      相关资源
      最近更新 更多