Download large file in Android
I have an app that downloads a very large file (over 50MB). Unfortunately I'm getting reports that the download fails.
Below is the logcat of one such failure, which ends with a java.net.SocketException: The operation timed out
. In-between it has various messages from the WifiMonitor
. I don't know how to interpret these messages.
Is there something special that I should do to download a large file, or is this simply a connection problem?
09-02 16:41:19.925 I/ActivityManager( 646): Displayed activity com.example/com.example.sp.MainActivity: 1110 ms (total 3786 ms)
09-02 16:41:21.935 W/InputManagerService( 646): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@45133d08
09-02 16:41:23.495 I/global ( 7345): Default buffer size used in BufferedInputStream constructor. It would be better to be explicit if an 8k buffer is required.
09-02 16:41:23.895 D/dalvikvm( 7345): GC freed 5348 objects / 307096 bytes in 160ms
09-02 16:41:25.885 D/dalvikvm( 7345): GC freed 15282 objects / 713544 bytes in 124ms
09-02 16:41:27.405 D/dalvikvm( 7345): GC freed 11775 objects / 524576 bytes in 131ms
09-02 16:41:28.982 I/wpa_supplicant( 7284): CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys
09-02 16:41:28.985 V/WifiMonitor( 646): Event [CTRL-EVENT-DISCONNECTED - Disconnect event - remove keys]
09-02 16:41:28.985 V/WifiStateTracker( 646): New network state is DISCONNECTED
09-02 16:41:28.985 I/wpa_supplicant( 7284): CTRL-EVENT-STATE-CHANGE id=0 state=0
09-02 16:41:28.985 V/WifiMonitor( 646): Event [CTRL-EVENT-STATE-CHANGE id=0 state=0]
09-02 16:41:28.995 V/WifiStateTracker( 646): Changing supplicant state: COMPLETED ==> DISCONNECTED
09-02 16:41:29.086 I/wpa_supplicant( 7284): CTRL-EVENT-STATE-CHANGE id=0 state=2
09-02 16:41:29.086 V/WifiMonitor( 646): Event [CTRL-EVENT-STATE-CHANGE id=0 state=2]
09-02 16:41:29.086 V/WifiStateTracker( 646): Changing supplicant state: DISCONNECTED ==> SCANNING
09-02 16:41:29.086 W/wpa_supplicant( 7284): Failed to initiate AP scan.
09-02 16:41:29.095 I/wpa_supplicant( 7284): CTRL-EVENT-SCAN-RESULTS Ready
09-02 16:41:29.095 I/wpa_supplicant( 7284): Trying to associate with 00:1c:f0:6e:2a:56 (SSID='WLANR' freq=2412 MHz)
09-02 16:41:29.095 E/wpa_supplicant( 7284): Set_key: Wrong Key
09-02 16:41:29.095 E/wpa_supplicant( 7284): Set_key: Wrong Key
09-02 16:41:29.095 E/wpa_supplicant( 7284): Set_key: Wrong Key
09-02 16:41:29.095 E/wpa_supplicant( 7284): Set_key: Wrong Key
09-02 16:41:29.095 E/wpa_supplicant( 7284): Set_key: Wrong Key
09-02 16:41:29.095 I/wpa_supplicant( 7284): CTRL-EVENT-STATE-CHANGE id=0 state=3
09-02 16:41:29.105 V/WifiMonitor( 646): Event [Trying to associate with 00:1c:f0:6e:2a:56 (SSID='WLANR' freq=2412 MHz)]
09-02 16:41:29.105 V/WifiMonitor( 646): Event [CTRL-EVENT-STATE-CHANGE id=0 state=3]
09-02 16:41:29.125 V/WifiStateTracker( 646): Changing supplicant state: SCANNING ==> ASSOCIATING
09-02 16:41:29.825 I/wpa_supplicant( 7284): CTRL-EVENT-STATE-CHANGE id=0 state=4
09-02 16:41:29.825 V/WifiMonitor( 646): Event [CTRL-EVENT-STATE-CHANGE id=开发者_如何学Go0 state=4]
09-02 16:41:29.825 V/WifiStateTracker( 646): Changing supplicant state: ASSOCIATING ==> ASSOCIATED
09-02 16:41:29.825 I/wpa_supplicant( 7284): Associated with 00:1c:f0:6e:2a:56
09-02 16:41:29.825 I/wpa_supplicant( 7284): CTRL-EVENT-STATE-CHANGE id=0 state=7
09-02 16:41:29.825 I/wpa_supplicant( 7284): CTRL-EVENT-CONNECTED - Connection to 00:1c:f0:6e:2a:56 completed (reauth) [id=0 id_str=]
09-02 16:41:29.825 I/wpa_supplicant( 7284): wpa_supplicant - IPC_EVENT_AUTH_SUCC
09-02 16:41:29.825 V/WifiMonitor( 646): Event [Associated with 00:1c:f0:6e:2a:56]
09-02 16:41:29.825 V/WifiMonitor( 646): Event [CTRL-EVENT-STATE-CHANGE id=0 state=7]
09-02 16:41:29.845 V/WifiStateTracker( 646): Changing supplicant state: ASSOCIATED ==> COMPLETED
09-02 16:41:29.855 V/WifiMonitor( 646): Event [CTRL-EVENT-CONNECTED - Connection to 00:1c:f0:6e:2a:56 completed (reauth) [id=0 id_str=]]
09-02 16:41:29.855 V/WifiStateTracker( 646): New network state is CONNECTED
09-02 16:41:29.865 D/WifiStateTracker( 646): Deconfiguring interface and stopping DHCP
09-02 16:41:29.865 E/wpa_supplicant( 7284): prepare_filter_struct: type=5
09-02 16:41:29.945 E/FileUtils( 7345): Download failed
09-02 16:41:29.945 E/FileUtils( 7345): java.net.SocketException: The operation timed out
The phone disconnects from Wi-Fi when going into sleep mode, which I guess was the cause here? Take a look at WifiManager's WifiLock to see how you can prevent it.
精彩评论