下载Android中大文件

下载Android中大文件

本文介绍了下载Android中大文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下载非常大的文件(超过50MB)的应用程序。不幸的是我得到报告称,下载失败。

下面是一个这样的失败,这与 java.net.SocketException异常结束的logcat的:操作超时。在两者之间具有从 WifiMonitor 的各种消息。我不知道该如何跨preT这些消息。

有没有一些特别的东西,我应该做下载一个大文件,或者是这只是一个连接问题?

  09-02 16:41:19.925 I / ActivityManager(646):显示活动com。示例/ com.example.sp.MainActivity:1110毫秒(共3786毫秒)
09-02 16:41:21.935 W / InputManagerService(646):窗口已经集中,忽视聚焦增益:com.android.internal.view.IInputMethodClient$Stub$Proxy@45133d08
09-02 16:41:23.495 I /全局(7345):默认缓冲区的BufferedInputStream构造用大小。它会更好,如果需要一个8K的缓冲区是明确的。
09-02 16:41:23.895 D / dalvikvm(7345):GC释放5348对象/在160毫秒307096字节
09-02 16:41:25.885 D / dalvikvm(7345):GC释放15282对象/在124ms 713544字节
09-02 16:41:27.405 D / dalvikvm(7345):GC释放11775对象/在131ms 524576字节
09-02 16:41:28.982 I /参考wpa_supplicant(7284):CTRL-EVENT-断开 - 断开事件 - 删除键
09-02 16:41:28.985 V / WifiMonitor(646):事件[CTRL-EVENT-断开 - 断开事件 - 删除键]
09-02 16:41:28.985 V / WifiStateTracker(646):新的网络状态断开
09-02 16:41:28.985 I /参考wpa_supplicant(7284):CTRL-EVENT-状态更改ID = 0 = 0的状态
09-02 16:41:28.985 V / WifiMonitor(646):事件[CTRL-EVENT-状态更改ID = 0状态= 0]
09-02 16:41:28.995 V / WifiStateTracker(646):改变请求者状态:已完成==> DISCONNECTED
09-02 16:41:29.086 I /参考wpa_supplicant(7284):CTRL-EVENT-状态更改ID = 0的状态= 2
09-02 16:41:29.086 V / WifiMonitor(646):事件[CTRL-EVENT-状态更改ID = 0的状态= 2]
09-02 16:41:29.086 V / WifiStateTracker(646):改变请求者状态:DISCONNECTED ==>扫描
09-02 16:41:29.086 W /参考wpa_supplicant(7284):无法启动AP扫描。
09-02 16:41:29.095 I /参考wpa_supplicant(7284):CTRL-EVENT-SCAN-结果就绪
09-02 16:41:29.095 I /参考wpa_supplicant(7284):试图以00相关联:1C:F0:6E:2A:56(SSID ='WLANR'频率= 2412兆赫)
09-02 16:41:29.095 E /参考wpa_supplicant(7284):Set_key:错键
09-02 16:41:29.095 E /参考wpa_supplicant(7284):Set_key:错键
09-02 16:41:29.095 E /参考wpa_supplicant(7284):Set_key:错键
09-02 16:41:29.095 E /参考wpa_supplicant(7284):Set_key:错键
09-02 16:41:29.095 E /参考wpa_supplicant(7284):Set_key:错键
09-02 16:41:29.095 I /参考wpa_supplicant(7284):CTRL-EVENT-状态更改ID = 0的状态= 3
09-02 16:41:29.105 V / WifiMonitor(646):事件[试图以00相关联:1C:F0:6E:2A:56(SSID ='WLANR'频率= 2412兆赫)
09-02 16:41:29.105 V / WifiMonitor(646):事件[CTRL-EVENT-状态更改ID = 0的状态= 3]
09-02 16:41:29.125 V / WifiStateTracker(646):改变请求者状态:扫描==>缔
09-02 16:41:29.825 I /参考wpa_supplicant(7284):CTRL-EVENT-状态更改ID = 0的状态= 4
09-02 16:41:29.825 V / WifiMonitor(646):事件[CTRL-EVENT-状态更改ID = 0的状态= 4]
09-02 16:41:29.825 V / WifiStateTracker(646):改变请求者状态:缔==> ASSOCIATED
09-02 16:41:29.825 I /参考wpa_supplicant(7284):关联以00:1C:F0:6E:2A:56
09-02 16:41:29.825 I /参考wpa_supplicant(7284):CTRL-EVENT-状态更改ID = 0的状态= 7
09-02 16:41:29.825 I /参考wpa_supplicant(7284):CTRL-EVENT-连接 - 连接到00:1C:F0:6E:2A:56结束(reauth)[ID = 0 = ID_STR]
09-02 16:41:29.825 I /参考wpa_supplicant(7284):参考wpa_supplicant - IPC_EVENT_AUTH_SUCC
16 09-02:41:29.825 V / WifiMonitor(646):事件相关[以00:1C:F0:6E:2A:56]
09-02 16:41:29.825 V / WifiMonitor(646):事件[CTRL-EVENT-状态更改ID = 0的状态= 7]
09-02 16:41:29.845 V / WifiStateTracker(646):改变请求者状态:与==>已完成
09-02 16:41:29.855 V / WifiMonitor(646):事件[CTRL-EVENT-连接 - 连接到00:1C:F0:6E:2A:56结束(reauth)[ID = 0 = ID_STR]
09-02 16:41:29.855 V / WifiStateTracker(646):新的网络状态连接
09-02 16:41:29.865的D / WifiStateTracker(646):解除配置接口和停止的DHCP
09-02 16:41:29.865 E /参考wpa_supplicant(7284):prepare_filter_struct:类型= 5
09-02 16:41:29.945 E / fileutils中(7345):下载失败
09-02 16:41:29.945 E / fileutils中(7345):java.net.SocketException异常:操作超时


解决方案

从Wi-Fi进入睡眠模式时,手机断开,我的猜测是原因吗?看看

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=0 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.

这篇关于下载Android中大文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 03:05