Android Development: How To Check If FTPFile Is a Directory? - android

In my app I have a ListView which I populate with names of files and folders in a directory for my file browser.
I have overrid the getView method so that I can manually set a different icon in each row of the ListView depending on the child's file type, or if it's a directory or not.
Now if I were to check if a path on the sdcard is a directory I'd simply do:
if(new File("/sdcard/folder/path").isDirectory()){
icon.setImageResource(R.drawable.foldericon);
}
But when dealing with FTPFile's that method doesn't seem to work.
Does anybody know how I can achieve the same outcome as the code above but with an FTPFile?

Related

Getting directory exists even deleted from gallery

I'm surprised when delete folder from gallery and getting that folder by programatically it's returning isExists() = true.
if(File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), directory).exists()) {
return true
}
Note: However it's happening mostly customised devices of android, is there any way to find directory is exists or not?
When you call File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), directory) you are actually creating folder and then you are checking for exist of that file, so you were always get true. Lookout documentation for constructor of File(File parent, String child).
Creates a new instance from a parent abstract
better to use concet string and get file like File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath()+ directory) to check exist or not.

How to read files from sdcard and show in listview?

I would like to create a button that when clicked will go to a class that displays all media files from an SD card using a ListView.
After selecting from the list it will then return the filename selected to the main class. IF the returned file is an image file, it will be displayed in an ImageView and if the returned file is an audio file, it'll display and on click play?
You may find it interesting to use a library to consult the files in a directory and display it. This can save you lots of work if the requirements of your application permits. There are a lot of libraries for this pourpose, for example:
https://github.com/bartwell/ExFilePicker
Hope it helps you!!

how to hide system folder of sdcard in android?

hi i want make simple file explorer which can display all folder of sdcard using listview and only display image file using gridview.i do all of this thing very well.Display in screen shot.but after this i handle the all folder structure of sdcard.also revers process will be handle successfully.but problem is there
when i click on the system folder like .android_secure ,secure ,asec then display Null pointer Exception.but i handle this if folder is empty then display Message folder is empty.
so what i can do now?how to handle this problem.
first i want hide this folder means does not display in listview. but can`t success.
please give me the way.
First Error Image
Now I add Next Point in this that i want to delete specific folder.so i use file.delete() but if the folder is not empty then what to do?
i also want delete this folder with all contain it`s possible with android2.2?
If you use File,
try
File file;
if(file.isfolder && file.list[] != null && file.isreadable()){ // check read,write access
imageView.setVisible(Visible)
}else{
// hide your list item data
}
or first check adapter data and then put it into adapter.
File files
// ... check files
Adapter adapter = new Adapter(files)
setListAdapter(adapter)

Show a list of all XML filenames in the res folder for an Android application

I'm simply trying to get a list of all the XML files in my res/xml folder. I have tried to use the asset manager .list() function, but that doesn't seem to return anything. I have tried other methods, but none seem to work. They either fail, or return nothing.
This is simply so I can show a ListView which contains the name of each file.
Does anyone have any ideas of what is necessary to do this?
Move them to assets/xml, then you can list them with assetManager.list("xml")

how to list the audio files in a Listview in android

I am new to this android application development.
I have a audio files in a particular directory. I want to list the those audio files in a listView.
please tell me how to do this activity.
Create a File object representing your directory on the SDcard and call appropriate File#list() variant to get list of all the files in that directory. You will get names of the files in a String[].
Create an Adapter class and pass this String array to it. Make a ListView and back it up by this custom Adapter.You can refer examples in API demos or this tutorial for the same

Categories

Resources