如何通过我的Android应用程序上的蓝牙访问连接到我的RFduino的microSD卡?

时间:2015-06-03 00:40:21

标签: android android-studio bluetooth-lowenergy mobile-application rfduino

我正在创建一个可以通过BLE连接到我的移动应用的设备。我的设备使用带有microSD屏蔽的RFduino微控制器。我的移动应用程序可以通过BLE连接到RFduino。我可以获得TX,RSSI,并从Phone应用程序向RFduino发送一些值。现在我无法通过移动应用程序访问microSD卡根路径。我希望能够显示文件资源管理器。我已经掌握了文件浏览器的基础知识,但它只是在屏幕上显示一个点。

这是我到目前为止所拥有的。我知道我需要指出路径,但我不确定如何。

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();
        }
    }
}

0 个答案:

没有答案