• Android之与当前连接的wifi进行文件夹的浏览与传输


    先上传jar文件;ConnectWifi.jar.zip

    上传源文件:org.zip

    使用实例及相应的注释;

    import java.io.File;
    import java.net.InetAddress;
    import org.swiftp.Defaults;
    import org.swiftp.FTPServerService;
    import org.swiftp.Globals;
    import org.swiftp.UiUpdater;
    import android.app.Activity;
    import android.content.Context;
    import android.content.Intent;
    import android.os.Bundle;
    import android.os.Environment;
    import android.os.Handler;
    import android.os.Message;
    import android.view.View;
    
    public class MainActivity extends Activity {
    
        private Context context;
        
        // 处理
        public Handler handler = new Handler() {
            public void handleMessage(Message msg) {
                switch (msg.what) {
                    case 0: // We are being told to do a UI update
                        // If more than one UI update is queued up, we only need to
                        // do one.
                        removeMessages(0);
                        updateUi();
                        break;
                    case 1: // We are being told to display an error message
                        removeMessages(1);
                }
            }
        };
        
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            context = this;
            
            // 实例化Globals
            Globals.setContext(context);
        }
    
        public void start(View view){
            
            Globals.setLastError(null);
            
            // 注册更新界面的handler
            UiUpdater.registerClient(handler);
            
            // 需要打开的对应目录
            File chrootDir = new File(Defaults.chrootDir);
            if (!chrootDir.isDirectory())
                return;
    
            // 打开FTP服务
            Intent intent = new Intent(context, FTPServerService.class);
    
            Globals.setChrootDir(chrootDir);
            if (!FTPServerService.isRunning()) {
                if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
                    context.startService(intent);
                    
                }
            } else {
                context.stopService(intent);
            }
        }
        
        // 绑定后的界面回调更新
        public void updateUi() {
             InetAddress address = FTPServerService.getWifiIp();
             if (address != null) {
                 String port = ":" + FTPServerService.getPort();
                 System.out.println("ftp://" + address.getHostAddress() + (FTPServerService.getPort() == 21 ? "" : port));
    
             } 
        }
        
        
        @Override
        protected void onStop() {
            super.onStop();
            // 反注册更新界面
            UiUpdater.unregisterClient(handler);
        }
    }
  • 相关阅读:
    浅析http缓存
    多级路由请求js文件路径不对的解决方法
    移动端屏幕适配原理以及方法讲解
    zoom与scale的异同
    querySelectorAll选择器的js实现
    垂直居中效果汇总
    windows配置php开发环境
    CentOS 6.2安装nagios
    Ganglia安装
    Ubuntu 14.04上安装Riak
  • 原文地址:https://www.cnblogs.com/lee0oo0/p/3390933.html
Copyright © 2020-2023  润新知