2015-04-22 47 views
0

首先基於其他答案,這裏是我已經完成的一些事情。Android JCIFS將文件寫入共享網絡文件夾(無法連接到服務器)

1-添加了正確的權限,以我的清單

2-使用一個子類的AsyncTask處理過程

3-只是出於好奇複製完全相同的代碼變成非的Adroid的Java項目,它工作正常。但是,在模擬器上它返回一個 '無法連接到服務器'

public class NetworkUploader extends AsyncTask<String,Void,String> { 
     private final String TAG = "SSTv1.0"; 

@Override 
protected String doInBackground(String... params) { 


     NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("","tom.smith", "abc123456"); 
     String sharepath = "smb://sed/Production/Test-Android/test.txt"; 
     try{ 
      String text = "Hello There"; 
      SmbFile sFile = new SmbFile(sharepath, auth); 
      SmbFileOutputStream out = new SmbFileOutputStream(sFile); 
     out.write(text.getBytes()); 
     out.close(); 
     }catch(Exception e){ 
      //e.printStackTrace(); 
      Log.d(TAG,e.getMessage()); 

     } 

    return null; 

} 



    @Override 
protected void onPostExecute(String result) { 
    //Do something with result 

} 

清單

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
package="au.net.toms.sst" > 
<uses-permission android:name="android.permission.CAMERA" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 
<uses-feature android:name="android.hardware.camera" /> 

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/AppTheme" > 
    <activity 
     android:name=".MainActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 

真的很感激任何反饋

回答

0

NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null,"tom.smith", "abc123456");

變化Ť他將字符串清空爲空。

相關問題