編輯:Android開發教程
import android.content.Context; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import com.mb.goods.app.BaseActivity; import com.mb.goods.app.R; import com.mb.goods.util.ServerFtplet; /** * 遠程管理 * @author pythoner * */ public class RemoteManagementActivity extends BaseActivity implements View.OnClickListener{ private Context context; private TextView tv_des; private EditText et_ftp; private WifiInfo wifiInfo; private boolean checked=false; private ServerFtplet ftp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_remote_management); context = this; WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); wifiInfo = wifiManager.getConnectionInfo(); ftp=ServerFtplet.getInstance(); initActionBar("遠程管理", null, null); initViews(); } @Override public void initViews() { // TODO Auto-generated method stub TextView tv_state=$(R.id.tv_state); tv_state.setText("網絡狀態\n"+wifiInfo.getSSID()); //0到-50表示信號最好,-50到-70表示信號偏差,小於-70表示最差,有可能連接不上或者掉線 int level=Math.abs(wifiInfo.getRssi()); ImageView tv_rssi=$(R.id.tv_rssi); tv_rssi.setImageLevel(level); tv_des=$(R.id.tv_des); et_ftp=$(R.id.et_ftp); $(R.id.btn_ok).setOnClickListener(this); } @Override public void updateViews(Object obj) { // TODO Auto-generated method stub } @Override public void updateTheme(int color) { super.updateTheme(color); setThemeDrawable(context, R.id.btn_ok); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.btn_ok: if(checked){ tv_des.setText("打開後可以在計算機上管理本設備上的文件"); et_ftp.setVisibility(View.GONE); et_ftp.setText(""); ((TextView)v).setText("打開"); ftp.stop(); }else{ tv_des.setText("在計算機中輸入:"); et_ftp.setVisibility(View.VISIBLE); et_ftp.setText("ftp://"+getIP()+":"+ServerFtplet.PORT+"/"); ((TextView)v).setText("關閉"); ftp.start(); } checked=!checked; break; default: break; } } @Override protected void onDestroy() { super.onDestroy(); ftp.stop(); } }
import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.ftpserver.FtpServer; import org.apache.ftpserver.FtpServerFactory; import org.apache.ftpserver.ftplet.Authority; import org.apache.ftpserver.ftplet.DefaultFtplet; import org.apache.ftpserver.ftplet.FtpException; import org.apache.ftpserver.ftplet.FtpRequest; import org.apache.ftpserver.ftplet.FtpSession; import org.apache.ftpserver.ftplet.Ftplet; import org.apache.ftpserver.ftplet.FtpletResult; import org.apache.ftpserver.ftplet.UserManager; import org.apache.ftpserver.listener.ListenerFactory; import org.apache.ftpserver.usermanager.PropertiesUserManagerFactory; import org.apache.ftpserver.usermanager.SaltedPasswordEncryptor; import org.apache.ftpserver.usermanager.impl.BaseUser; import org.apache.ftpserver.usermanager.impl.WritePermission; import android.os.Environment; /** * 利用Android設備作為FTP服務器 * @author Ni Guijun * */ public class ServerFtplet extends DefaultFtplet { public static final int PORT = 3333; // public static final String directory = Environment.getExternalStorageDirectory().getPath();//指定SD卡根目錄 public static final String directory = Environment.getExternalStorageDirectory().getPath() + "/cloudStore/data/";//指定到SD卡某個目錄 private FtpServer mFtpServer; private boolean isAnonymous = true;//是否需要匿名登陸 private final String mUser = "admin";//非匿名登陸時的賬戶 private final String mPassword = ""; private static ServerFtplet mInstance; public static ServerFtplet getInstance() { if (mInstance == null) { mInstance = new ServerFtplet(); } return mInstance; } /** * FTP啟動 * * @throws FtpException */ public void start(){ try{ if (null != mFtpServer && false == mFtpServer.isStopped()) { return; } File file = new File(directory); if (!file.exists()) { file.mkdirs(); } FtpServerFactory serverFactory = new FtpServerFactory(); ListenerFactory listenerFactory = new ListenerFactory(); // 設定端末番號 listenerFactory.setPort(PORT); // 通過PropertiesUserManagerFactory創建UserManager然後向配置文件添加用戶 PropertiesUserManagerFactory userManagerFactory = new PropertiesUserManagerFactory(); userManagerFactory.setPasswordEncryptor(new SaltedPasswordEncryptor()); UserManager userManager = userManagerFactory.createUserManager(); List<Authority> auths = new ArrayList<Authority>(); Authority auth = new WritePermission(); auths.add(auth); // 添加用戶 BaseUser user = new BaseUser(); if(isAnonymous){ user.setName("anonymous");//匿名登陸,不需要密碼 }else{ user.setName(mUser); user.setPassword(mPassword); user.setAuthorities(auths); } user.setHomeDirectory(directory); userManager.save(user); // 設定Ftplet Map<String, Ftplet> ftpletMap = new HashMap<String, Ftplet>(); ftpletMap.put("Ftplet", this); serverFactory.setUserManager(userManager); serverFactory.addListener("default", listenerFactory.createListener()); serverFactory.setFtplets(ftpletMap); // 創建並啟動FTPServer mFtpServer = serverFactory.createServer(); mFtpServer.start(); }catch(FtpException e){ e.printStackTrace(); } } /** * FTP停止 */ public void stop() { // FtpServer不存在和FtpServer正在運行中 if (null != mFtpServer && false == mFtpServer.isStopped()) { mFtpServer.stop(); mFtpServer=null; } } @Override public FtpletResult onAppendStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return super.onAppendStart(session, request); } @Override public FtpletResult onAppendEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { return super.onAppendEnd(session, request); } @Override public FtpletResult onLogin(FtpSession session, FtpRequest request) throws FtpException, IOException { return super.onLogin(session, request); } @Override public FtpletResult onConnect(FtpSession session) throws FtpException, IOException { return super.onConnect(session); } @Override public FtpletResult onDisconnect(FtpSession session) throws FtpException, IOException { return super.onDisconnect(session); } @Override public FtpletResult onUploadStart(FtpSession session, FtpRequest request) throws FtpException, IOException { return super.onUploadStart(session, request); } @Override public FtpletResult onUploadEnd(FtpSession session, FtpRequest request) throws FtpException, IOException { String FtpUploadPath = directory + request.getArgument(); // 接收到文件後立即刪除 File uploadFile = new File(FtpUploadPath); uploadFile.delete(); return super.onUploadEnd(session, request); } }
package net.gimite.nativeexe; import java.io.BufferedReader; import java.io.F
除了使用Notification之外,Toast也可以用來通知用戶某件事發生了,Toast為一個透明的對話框,可以在屏幕上顯示幾秒 鐘後自動消失。功能上有點類似Tool
1.1 Gralloc與Framebuffer相信做過Linux開發的人對framebuffer不會太陌生,它是內核系統提供的一個與硬件無關的顯示抽象層。之所以稱之為bu
Android平台, 可以使用本地資源, 也可以使用系統資源;使用靜態R類訪問資源, R類中包含一個靜態子類, R類中每一個子類都把它的相關資源表示為變量的形式;資源表被