我发现此代码用于浏览文件夹,但它对我的录音机没用我想重命名、删除和共享录音机文件夹中的录制文件,但我不知道该怎么做。
import java.io.File;
import java.util.ArrayList;
import android.content.Intent;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;
import android.util.Log;
import java.util.List;
import java.util.Collections;
import android.widget.ArrayAdapter;
import android.app.*;
import android.os.*;
public class MainActivity extends ListActivity {
private String path;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Use the current directory as title
path = "/mnt/sdcard/Abzarak/VoiceRecorder";
if (getIntent().hasExtra("path")) {
path = getIntent().getStringExtra("path");
}
setTitle(path);
// Read all files sorted into the values-array
List values = new ArrayList();
File dir = new File(path);
if (!dir.canRead()) {
setTitle(getTitle() + " (inaccessible)");
}
String[] list = dir.list();
if (list != null) {
for (String file : list) {
if (!file.startsWith(".")) {
values.add(file);
}
}
}
Collections.sort(values);
// Put the data into the list
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_2, android.R.id.text1, values);
setListAdapter(adapter);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
String filename = (String) getListAdapter().getItem(position);
if (path.endsWith(File.separator)) {
filename = path + filename;
} else {
filename = path + File.separator + filename;
}
if (new File(filename).isDirectory()) {
Intent intent = new Intent(this, MainActivity.class);
intent.putExtra("path", filename);
startActivity(intent);
} else {
Toast.makeText(this, filename + " is not a directory", Toast.LENGTH_LONG).show();
}
}
}
我设法通过添加打开录制的文件:
import android.net.uri;
并把这个代替吐司:
} else {
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
File file = new File(filename);
intent.setDataAndType(Uri.fromFile(file), "audio/*");
startActivity(intent);
}
但我仍然不知道如何删除或重命名或共享录制的文件,我不知道要添加什么。