简体   繁体   中英

Android JCIFS write file to shared network folder (Can't connect to server)

Firstly based on other answers here are some things I have already done.

1- Added the correct permissions to my manifest

2- Used an AsyncTask subclass to handle the process

3- Just out of curiosity copied the exact same code into a non adroid java project and it works fine. But on the emulator it returns a 'could not connect to the server'

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

}

Manifest

<?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>

Really appreciate any feedback

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

将空字符串更改为null。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM