Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Use this code, </p> <pre><code>public class RecordedVideos extends ListActivity { private List&lt;String&gt; item = null; private List&lt;String&gt; path = null; private String root="/sdcard/Recorded Videos"; private TextView myPath; Button back; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.filelist); back=(Button)findViewById(R.id.back); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2, long arg3) { File file = new File(path.get(arg2)); boolean b=file.delete(); return false; } }); myPath = (TextView)findViewById(R.id.path); getDir(root); back.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub finish(); } }); } private void getDir(String dirPath) { myPath.setText("Location: " + dirPath); item = new ArrayList&lt;String&gt;(); path = new ArrayList&lt;String&gt;(); 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 &lt; files.length; i++) { File file = files[i]; path.add(file.getPath()); if(file.isDirectory()) item.add(file.getName() + "/"); else item.add(file.getName()); } ArrayAdapter&lt;String&gt; fileList = new ArrayAdapter&lt;String&gt;(this, R.layout.row, item); setListAdapter(fileList); } protected void onListItemClick(ListView l, View v, int position, long id) { File file = new File(path.get(position)); if (file.isDirectory()) { if(file.canRead()) getDir(path.get(position)); else { new AlertDialog.Builder(this) .setIcon(R.drawable.icon) .setTitle("[" + file.getName() + "] folder can't be read!") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }).show(); } } else { /*new AlertDialog.Builder(this) .setIcon(R.drawable.icon) .setTitle("[" + file.getName() + "]") .setPositiveButton("OK", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }).show(); */ Intent intent= new Intent(); intent.setAction(Intent.ACTION_VIEW); Uri filetype= Uri.parse("file://" + file.getPath()); String filename=file.getName(); if(filename.endsWith(".txt")||filename.endsWith(".doc")) { intent.setDataAndType(filetype, "text/*"); startActivity(intent); } else if(filename.endsWith(".gif")||filename.endsWith(".jpg")||filename.endsWith(".png")) { intent.setDataAndType(filetype, "image/*"); startActivity(intent); } else if(filename.endsWith(".mp4")||filename.endsWith(".3gp")) { intent.setDataAndType(filetype, "video/*"); startActivity(intent); } else { intent.setDataAndType(filetype, "audio/*"); startActivity(intent); } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload