Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python浏览Android设备的目录_Android_Python_Adb - Fatal编程技术网

使用Python浏览Android设备的目录

使用Python浏览Android设备的目录,android,python,adb,Android,Python,Adb,我希望我的用户能够在点击“浏览”按钮时查看和浏览Android设备的目录,这样他们就能够选择存储照片的文件夹 到目前为止,我可以进入“adb外壳”,但在通过adb外壳连接到设备时,我无法输入更多的命令进行交互。我想通过adb外壳和cd连接到设备,或者在连接到设备后运行其他命令。我当前的代码非常糟糕,因为我不明白“stdout=subprocess.PIPE”是什么意思,我只是在学习一些在线教程 这是我目前的代码: from subprocess import check_output impor

我希望我的用户能够在点击“浏览”按钮时查看和浏览Android设备的目录,这样他们就能够选择存储照片的文件夹

到目前为止,我可以进入“adb外壳”,但在通过adb外壳连接到设备时,我无法输入更多的命令进行交互。我想通过adb外壳和cd连接到设备,或者在连接到设备后运行其他命令。我当前的代码非常糟糕,因为我不明白“stdout=subprocess.PIPE”是什么意思,我只是在学习一些在线教程

这是我目前的代码:

from subprocess import check_output
import subprocess

out = check_output("adb shell ls")

print out

destination = raw_input("Choose a folder: ")

p = subprocess.Popen("adb shell",stdout=subprocess.PIPE)
out, err = p.communicate()

g = subprocess.call(['cd', destination], stdout=subprocess.PIPE)
out, err = g.communicate()

print out

我感谢任何帮助和指导。提前谢谢。

我建议您使用Android功能来迭代目录和文件。例如,如果您正在使用Java创建一个新文件(可能会更容易),那么您可以创建一个新文件:

您可以使用所有这些关于文件的信息在ListView或GridView中显示它们,单击特定项目,您可以更新currentDir并刷新内容或打开文件,等等


下面是一个文件选择器的示例

Hi,感谢您的及时回复。我正在用Python编写代码,如果您能够指导我学习Python语法,我将不胜感激(同时我将尝试自己用Python编写代码)。您知道在“adb外壳”模式下,是否可以使用adb连接到adb外壳并输入更多命令?非常感谢。您如何为Android编写python应用程序?你使用的是框架库吗?如果是,它应该已经有了一些功能。我在kyvi.org上找到了这一个,对于一些附加功能,您可以连接到它一些模块,它似乎有一个创建文件选择器的示例(使用框架的函数)。下面是一个类似的问题和答案:
File currentDir = new File("/"); // "/" stands for root directory
File[] files = currentDir.listFiles(); // lists all files in the current directory, store them in the *files* array 
//you can supply as an argument a String[] array, with the file extensions if needed 
//(to show only .jpeg, .png, or only documents like .docx, .pdf)
//you can use Collections and Comparator classes to sort them
if(files != null && files.length > 0) { //check if it holds any files
        for(File f : files) {
            if(f.isHidden()) { 
                // don't add the hidden file to the list, or at your choice
                continue;
            } else {
            // add the file to the list
            fileList.add(f);
            }
        }
        Collections.sort(fileList, new FileComparator()); //
}
//you can also check if a specific *file* is file or directory with
file.isFile();
file.isDirectory();