0

I am creating a device that will connect to my mobile app via BLE. My device is using a RFduino microcontroller with a microSD shield. My mobile app can connect to the RFduino via BLE. I can get the TX, RSSI, and send some value from the Phone app to the RFduino. Now I am having trouble accessing the microSD card root path through the mobile app. I would like to be able to display a file explorer. I already have the basics for the file explorer, but it is just displaying a dot on the screen.

This is what I have so far. I know I need to point the path, but I'm not exactly sure how.

import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;



public class AndroidExplorer extends ListActivity {

    private List<String> item = null;
    private List<String> path = null;
    private String root="/";
    private TextView myPath;

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_view_files);
        myPath = (TextView)findViewById(R.id.path);
        getDir(root);
    }

    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();
        Arrays.sort(files);

        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];
            path.add(file.getPath());
            if(file.isDirectory())
                item.add(file.getName() + "/");
            else
                item.add(file.getName());
        }

        ArrayAdapter<String> fileList =
                new ArrayAdapter<String>(this, R.layout.row, item);
        setListAdapter(fileList);
    }

    @Override

    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.mipmap.ic_launcher)
                        .setTitle("[" + file.getName() + "] folder can't be read!")
                        .setPositiveButton("OK",
                                new DialogInterface.OnClickListener() {

                                    @Override

                                    public void onClick(DialogInterface dialog, int which) {
                                        // TODO Auto-generated method stub
                                    }
                                }).show();
            }

        } else {
            new AlertDialog.Builder(this)
                    .setIcon(R.mipmap.ic_launcher)
                    .setTitle("[" + file.getName() + "]")
                    .setPositiveButton("OK",
                            new DialogInterface.OnClickListener() {

                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    // TODO Auto-generated method stub
                                }
                            }).show();
        }
    }
}
  • You do know you will have to do a shed load of work to map some sort of file protocol onto your own BLE based protocol and then code it all up at both ends. This is a very none trivial project. BLE is not the right underlying protocol to do it. Classic Bluetooth would be far easier and you can probably fine some suitable code to get you going. – Ifor Jun 03 '15 at 11:28
  • Hmm. That sounds difficult. I'd much rather switch it to Bluetooth, but my group is insisting that we stick with what we have because of a time crunch. We'll see. Thanks though. – Trish Spraggins Jun 05 '15 at 02:46

0 Answers0