File tree Expand file tree Collapse file tree 3 files changed +37
-3
lines changed
java/com/loopj/android/http/sample Expand file tree Collapse file tree 3 files changed +37
-3
lines changed Original file line number Diff line number Diff line change 9
9
<application
10
10
android : icon =" @drawable/ic_launcher"
11
11
android : label =" @string/app_name"
12
+ android : name =" .SampleApplication"
12
13
android : theme =" @style/AppTheme" >
13
14
<activity android : name =" .WaypointsActivity" >
14
15
<intent-filter >
Original file line number Diff line number Diff line change
1
+ package com .loopj .android .http .sample ;
2
+
3
+ import android .annotation .TargetApi ;
4
+ import android .app .Application ;
5
+ import android .os .Build ;
6
+ import android .os .StrictMode ;
7
+ import android .util .Log ;
8
+
9
+ public class SampleApplication extends Application {
10
+
11
+ private static final String LOG_TAG = "SampleApplication" ;
12
+
13
+ @ Override
14
+ public void onCreate () {
15
+ setStrictMode ();
16
+ super .onCreate ();
17
+ }
18
+
19
+ @ TargetApi (Build .VERSION_CODES .HONEYCOMB )
20
+ private void setStrictMode () {
21
+ if (Integer .valueOf (Build .VERSION .SDK ) > 3 ) {
22
+ Log .d (LOG_TAG , "Enabling StrictMode policy over Sample application" );
23
+ StrictMode .setThreadPolicy (new StrictMode .ThreadPolicy .Builder ()
24
+ .detectAll ()
25
+ .penaltyLog ()
26
+ .penaltyDeath ()
27
+ .build ());
28
+ StrictMode .setVmPolicy (new StrictMode .VmPolicy .Builder ()
29
+ .detectAll ()
30
+ .penaltyLog ()
31
+ .build ());
32
+ }
33
+ }
34
+ }
Original file line number Diff line number Diff line change 18
18
19
19
package com .loopj .android .http .sample .util ;
20
20
21
- import android .annotation . TargetApi ;
21
+ import android .os . Build ;
22
22
import android .util .Log ;
23
23
24
24
import com .loopj .android .http .AsyncHttpClient ;
@@ -181,10 +181,9 @@ public Socket createSocket() throws IOException {
181
181
* @param host Hostname to connect to
182
182
* @see <a href="https://code.google.com/p/android/issues/detail?id=13117#c14">https://code.google.com/p/android/issues/detail?id=13117#c14</a>
183
183
*/
184
- @ TargetApi (4 )
185
184
private void injectHostname (Socket socket , String host ) {
186
185
try {
187
- if (android . os . Build .VERSION .SDK_INT < 14 ) {
186
+ if (Integer . valueOf ( Build .VERSION .SDK ) >= 4 ) {
188
187
Field field = InetAddress .class .getDeclaredField ("hostName" );
189
188
field .setAccessible (true );
190
189
field .set (socket .getInetAddress (), host );
You can’t perform that action at this time.
0 commit comments