Bonjour,
Je débute en programmation Java sous Android, mes connaissances en Java sont très limitées (mais j'essaie de m'accrocher)...
Jusqu'à présent j'arrivais à m'en sortir grâce aux Tuto ou aux discussions sur le forum mais là je bloque depuis quelques jours...
Voici mon soucis, je me suis lancé dans une petite application qui permet , entre autres, de créer un fichier dans un répertoire partagé sur un PC (Windows Vista).
Le répertoire partagé "test" est à la racine c:\. L'adresse IP du PC est 192.168.1.4.
Le login et mot de passe du PC pour ouvrir la session sont respectivement "user" et "psswd".
J'ai installé la librairie jcifs-1-3.17.jar.
Au niveau du manifest, voici les permissions :
et voici le code implémenté dans MainActivity :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 public void NextClick() throws IOException { NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("","user","psswd"); SmbFile destinationfile = new SmbFile("smb://192.168.1.4/test/essai.txt",auth); SmbFileOutputStream sfos = new SmbFileOutputStream(destinationfile); sfos.write("essai test".getBytes()); sfos.close();
et pour finir voici le log cat :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 08-08 09:39:10.960: I/System.out(16652): Sending WAIT chunk 08-08 09:39:10.960: W/ActivityThread(16652): Application pack.qcm_demo is waiting for the debugger on port 8100... 08-08 09:39:11.100: I/dalvikvm(16652): Debugger is active 08-08 09:39:11.160: I/System.out(16652): Debugger has connected 08-08 09:39:11.160: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:11.360: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:11.560: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:11.760: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:11.960: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:12.165: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:12.365: I/System.out(16652): waiting for debugger to settle... 08-08 09:39:12.565: I/System.out(16652): debugger has settled (1310) 08-08 09:39:12.915: E/SensorManager(16652): thread start 08-08 09:39:12.915: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c97d58 08-08 09:39:12.935: D/SensorManager(16652): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c97d58 08-08 09:39:12.935: D/Sensors(16652): Remain listener = Sending .. normal delay 200ms 08-08 09:39:12.935: I/Sensors(16652): sendDelay --- 200000000 08-08 09:39:12.935: D/SensorManager(16652): JNI - sendDelay 08-08 09:39:12.935: I/SensorManager(16652): Set normal delay = true 08-08 09:39:12.980: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c97d58 08-08 09:39:13.040: D/libEGL(16652): loaded /system/lib/egl/libEGL_mali.so 08-08 09:39:13.055: D/libEGL(16652): loaded /system/lib/egl/libGLESv1_CM_mali.so 08-08 09:39:13.055: D/libEGL(16652): loaded /system/lib/egl/libGLESv2_mali.so 08-08 09:39:13.060: D/(16652): Device driver API match 08-08 09:39:13.060: D/(16652): Device driver API version: 10 08-08 09:39:13.060: D/(16652): User space API version: 10 08-08 09:39:13.060: D/(16652): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 15:37:13 KST 2012 08-08 09:39:13.105: D/OpenGLRenderer(16652): Enabling debug mode 0 08-08 09:39:19.640: D/SensorManager(16652): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c97d58 08-08 09:39:19.640: D/Sensors(16652): Remain listener = Sending .. normal delay 200ms 08-08 09:39:19.640: I/Sensors(16652): sendDelay --- 200000000 08-08 09:39:19.640: D/SensorManager(16652): JNI - sendDelay 08-08 09:39:19.640: I/SensorManager(16652): Set normal delay = true 08-08 09:39:19.900: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41cbf590 08-08 09:39:19.920: D/SensorManager(16652): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41cbf590 08-08 09:39:19.920: D/Sensors(16652): Remain listener = Sending .. normal delay 200ms 08-08 09:39:19.920: I/Sensors(16652): sendDelay --- 200000000 08-08 09:39:19.920: D/SensorManager(16652): JNI - sendDelay 08-08 09:39:19.920: I/SensorManager(16652): Set normal delay = true 08-08 09:39:19.945: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41cbf590 08-08 09:39:20.075: D/SensorManager(16652): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41cbf590 08-08 09:39:20.080: D/Sensors(16652): Remain listener = Sending .. normal delay 200ms 08-08 09:39:20.080: I/Sensors(16652): sendDelay --- 200000000 08-08 09:39:20.080: D/SensorManager(16652): JNI - sendDelay 08-08 09:39:20.080: I/SensorManager(16652): Set normal delay = true 08-08 09:39:20.165: D/dalvikvm(16652): GC_CONCURRENT freed 110K, 6% free 12468K/13127K, paused 14ms+12ms, total 41ms 08-08 09:39:20.255: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c9bd90 08-08 09:39:20.270: D/SensorManager(16652): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c9bd90 08-08 09:39:20.270: D/Sensors(16652): Remain listener = Sending .. normal delay 200ms 08-08 09:39:20.270: I/Sensors(16652): sendDelay --- 200000000 08-08 09:39:20.270: D/SensorManager(16652): JNI - sendDelay 08-08 09:39:20.270: I/SensorManager(16652): Set normal delay = true 08-08 09:39:20.275: W/IInputConnectionWrapper(16652): showStatusIcon on inactive InputConnection 08-08 09:39:20.295: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c9bd90 08-08 09:39:20.455: W/IInputConnectionWrapper(16652): getSelectedText on inactive InputConnection 08-08 09:39:20.460: W/IInputConnectionWrapper(16652): setComposingText on inactive InputConnection 08-08 09:39:20.460: W/IInputConnectionWrapper(16652): getExtractedText on inactive InputConnection 08-08 09:39:30.525: D/SensorManager(16652): unregisterListener:: Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c9bd90 08-08 09:39:30.525: D/Sensors(16652): Remain listener = Sending .. normal delay 200ms 08-08 09:39:30.525: I/Sensors(16652): sendDelay --- 200000000 08-08 09:39:30.525: D/SensorManager(16652): JNI - sendDelay 08-08 09:39:30.525: I/SensorManager(16652): Set normal delay = true 08-08 09:39:30.605: W/IInputConnectionWrapper(16652): getSelectedText on inactive InputConnection 08-08 09:39:30.605: W/IInputConnectionWrapper(16652): setComposingText on inactive InputConnection 08-08 09:39:30.605: W/IInputConnectionWrapper(16652): getExtractedText on inactive InputConnection 08-08 09:39:32.485: D/SensorManager(16652): registerListener :: handle = 0 name= LSM330DLC 3-axis Accelerometer delay= 200000 Listener= android.view.OrientationEventListener$SensorEventListenerImpl@41c9bd90 08-08 09:39:36.570: W/dalvikvm(16652): Exception Landroid/os/NetworkOnMainThreadException; thrown while initializing Ljcifs/netbios/NbtAddress; 08-08 09:39:36.570: W/dalvikvm(16652): Exception Ljava/lang/ExceptionInInitializerError; thrown while initializing Ljcifs/UniAddress; 08-08 09:39:36.570: D/AndroidRuntime(16652): Shutting down VM 08-08 09:39:36.570: W/dalvikvm(16652): threadid=1: thread exiting with uncaught exception (group=0x4101d2a0) 08-08 09:39:36.600: E/AndroidRuntime(16652): FATAL EXCEPTION: main 08-08 09:39:36.600: E/AndroidRuntime(16652): java.lang.ExceptionInInitializerError 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFile.getFirstAddress(SmbFile.java:864) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFile.connect(SmbFile.java:951) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFile.connect0(SmbFile.java:880) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFile.open0(SmbFile.java:972) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFile.open(SmbFile.java:1006) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:97) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:67) 08-08 09:39:36.600: E/AndroidRuntime(16652): at pack.qcm_demo.MainActivity.NextClick(MainActivity.java:162) 08-08 09:39:36.600: E/AndroidRuntime(16652): at pack.qcm_demo.MainActivity$10.onClick(MainActivity.java:137) 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.view.View.performClick(View.java:4211) 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.view.View$PerformClick.run(View.java:17267) 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.os.Handler.handleCallback(Handler.java:615) 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.os.Handler.dispatchMessage(Handler.java:92) 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.os.Looper.loop(Looper.java:137) 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.app.ActivityThread.main(ActivityThread.java:4898) 08-08 09:39:36.600: E/AndroidRuntime(16652): at java.lang.reflect.Method.invokeNative(Native Method) 08-08 09:39:36.600: E/AndroidRuntime(16652): at java.lang.reflect.Method.invoke(Method.java:511) 08-08 09:39:36.600: E/AndroidRuntime(16652): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006) 08-08 09:39:36.600: E/AndroidRuntime(16652): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773) 08-08 09:39:36.600: E/AndroidRuntime(16652): at dalvik.system.NativeStart.main(Native Method) 08-08 09:39:36.600: E/AndroidRuntime(16652): Caused by: java.lang.ExceptionInInitializerError 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.UniAddress.<clinit>(UniAddress.java:62) 08-08 09:39:36.600: E/AndroidRuntime(16652): ... 21 more 08-08 09:39:36.600: E/AndroidRuntime(16652): Caused by: android.os.NetworkOnMainThreadException 08-08 09:39:36.600: E/AndroidRuntime(16652): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118) 08-08 09:39:36.600: E/AndroidRuntime(16652): at java.net.InetAddress.lookupHostByName(InetAddress.java:385) 08-08 09:39:36.600: E/AndroidRuntime(16652): at java.net.InetAddress.getLocalHost(InetAddress.java:365) 08-08 09:39:36.600: E/AndroidRuntime(16652): at jcifs.netbios.NbtAddress.<clinit>(NbtAddress.java:187) 08-08 09:39:36.600: E/AndroidRuntime(16652): ... 22 more 08-08 09:39:52.665: I/Process(16652): Sending signal. PID: 16652 SIG: 9
J'ai effectué des recherches sur le web et en particulier dans ce forum. J'ai trouvé des quelques infos sur les "smbfiles" mais je ne trouve pas quelles erreurs j'ai pu commettre ( il y en a sûrement.... )
J'ai également essayé avec un pc sous windows XP même soucis.
Le smartphone ainsi que le PC sous simplement reliés sur le même réseau WIFI, aucune configuration particulière.
Si vous avez une piste de solution, cela m'aiderait énormément.
D'avance un grand merci pour votre aide.
Jean-François
(qui vous adresse un peu de soleil de la Réunion , je crois que vous êtes sous les orages.)
Partager