gpt4 book ai didi

android - 如何通过代码打开内置文件管理器

转载 作者:行者123 更新时间:2023-11-30 03:43:13 24 4
gpt4 key购买 nike

我的手机中有一个内置的文件管理器。我如何通过我的应用程序中的代码调用它。

最佳答案

我写了自己的文件管理器,如下所示。可能对大家有用。

试试这个,如果我错了请纠正我

public class FileManager extends Activity {

private String[] basePath = {Environment.getExternalStorageDirectory() + "", "/mnt/sdcard2"};

private ListView listView;

private ArrayList<String> pathList;
ArrayAdapter<String> adapter;
private ArrayList<String> fileList;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_file_manager);

listView = (ListView)findViewById(R.id.listView);

fileList = new ArrayList<String>();
pathList = new ArrayList<String>();

adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, fileList);
loadBasedata();
listView.setAdapter(adapter);

listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

// Path is hardcoded
if(pathList.size() == 0)
pathList.add(basePath[0]);
else
pathList.add(pathList.get(pathList.size() - 1) + "/" + fileList.get(position));
fileList.clear();
// Add new files to list
addFilesToList(pathList.get(pathList.size() - 1));
adapter.notifyDataSetChanged();
}
});
}
private void loadBasedata() {
fileList.clear();

fileList.add("Internal sdcard");
File file = new File(basePath[1]);
if(file.exists())
{
fileList.add("External sdcard");
}
adapter.notifyDataSetChanged();
}
@Override
public void onBackPressed() {

if(pathList.isEmpty())
finish();
else if(pathList.size() == 1)
{
pathList.clear();
loadBasedata();
}
else
{
fileList.clear();
pathList.remove(pathList.size() - 1);
addFilesToList(pathList.get(pathList.size() - 1));
adapter.notifyDataSetChanged();
}
}
private void addFilesToList(String path) {
File parentDir = new File(path);

if(parentDir.isDirectory())
{
File[] files = parentDir.listFiles();
//this.adapter.add("Go Back");
for(int i = 0; i < files.length; i++)
{
String filename=files[i].getName();
fileList.add(filename);
}
}
}

关于android - 如何通过代码打开内置文件管理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com