2012年7月25日 星期三

FTP client


找尋可在Android上使用的FTP client library,用於傳輸檔案到FTP server中
  • edtFTPJ
    • License: LGPL
    • 付費版具Security
  • FTPClient
    • License: ASF
決定使用FTPClient
  • 將上面二種library參考到Android程式當中,皆會發生NoClassDefFoundError
    • 解法:將library直接匯入到程式的libs資料夾中
  • 由於上面的原因,故採用較小容量的FTPClient
Usage
public class MainActivity extends Activity {

 private static final String TAG = "MainActivity";
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int port = 21;
        
        String ftpAddress = "127.0.0.1";
        String username = "potato";
        String password = "123456";
        String root = "/sdcard";
        String remoteRoot = "/test";
        
        FileInputStream inputStream = null;  
        FTPClient client = null;

        try {
            client = new FTPClient();            

            client.setConnectTimeout(1000);
            client.connect(ftpAddress, port);
            client.login(username, password);
            
            client.setFileType(FTP.BINARY_FILE_TYPE);
            client.enterLocalPassiveMode();

            for(int i = 0;i<3;i++)
            {
             try {
          inputStream = new FileInputStream(root + "/" + i + ".jpg");
          } catch (FileNotFoundException e) {
           e.printStackTrace();
          }
                client.appendFile(remotRoot + "/" + i + ".jpg", inputStream);
             inputStream.close();
            }            
            client.disconnect();
            
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        
    }
}

2012年7月9日 星期一

在Facebook Developer登記application

  1. 建立一個應用程式



  2. 製作Android app的key,藉由cmd (藉由eclipse)



  3. 將key轉為hash key供facebook developer使用 (需先裝openssl)



  4. 編輯App



  5. 將hash key加入app



  6. 複製APPID放入APP中



Reference: 開發雜記