我该如何解决这个问题。 在文件资源管理器中,当我点击视频文件时。 alertdialog中出现了其他内容。它理论上应该发生,压缩文件。
我该如何解决? 谢谢。 我添加了2张照片,以便更好地理解错误。
public class file_explorer_fragment extends ListFragment {
private List<String> item = null;
private List<String> path = null;
private String root;
private TextView myPath;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.activity_file_explorer_fragment, container, false);
myPath = (TextView)v.findViewById(R.id.path);
root = Environment.getExternalStorageDirectory().getPath();
getDir(root);
return v;
}
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];
if(!file.isHidden() && file.canRead()) {
path.add(file.getPath());
if(file.isDirectory()){
item.add(file.getName() + "/");
}else{
if(isVideo(file)){
item.add(file.getName());
}
}
}
}
ArrayAdapter<String> fileList =
new ArrayAdapter<String>(getActivity(), R.layout.row_file_explorer, item);
setListAdapter(fileList);
}
public static boolean isVideo(File file){
//merge perfect codul asta
/*{
if (file.getName().toLowerCase().endsWith(".avi")) return true;
if (file.getName().toLowerCase().endsWith(".m3u8")) return true;
if (file.getName().toLowerCase().endsWith(".3gp")) return true;
if (file.getName().toLowerCase().endsWith(".mpg")) return true;
if (file.getName().toLowerCase().endsWith(".mp4")) return true;
return false;
}*/
String extension = "";
String filename = file.getName().toLowerCase();
int i = filename.lastIndexOf('.');
if (i >= 0) {
extension = filename.substring(i);
}
/* String ext = null;
String s = file.getName();
int i = s.lastIndexOf('.');
if (i > 0 && i < s.length() - 1) {
ext = s.substring(i).toLowerCase();
}*/
switch (extension) {
case ".3gp":
case ".mpg":
case ".mpeg":
case ".mpe":
case ".mp4":
case ".avi":
case ".m3u8":
return true;
default:
return false;
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
File file = new File(path.get(position));
Context context = getActivity().getApplicationContext();
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, path.get(position), duration);
toast.show();
if (file.isDirectory())
{
if(file.canRead()){
getDir(path.get(position));
}else{
new android.app.AlertDialog.Builder(getActivity())
.setIcon(R.drawable.ic_folder_open_black_24dp)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK", null).show();
}
}else {
new android.app.AlertDialog.Builder(getActivity())
.setIcon(R.drawable.ic_folder_open_black_24dp)
.setTitle(file.getName())
.setPositiveButton("OK", null).show();
//Intent intent = new Intent(getActivity(), MainActivity.class);
//intent.putExtra("url", root+"/"+file.getName());
//startActivity(intent);
}
}
}
来自节目2视频的照片。