Strict mode in android 2.2

后端 未结 6 582
庸人自扰
庸人自扰 2020-12-06 03:56

I have target sdk set as 3.2 and min sdk as 2.2, how can I use strictmode in my application, as I understand it is introduced but cannot really understand how to start using

6条回答
  •  庸人自扰
    2020-12-06 04:20

    Set the Android Manifest to something like this.

    
    

    Use the below code in the onCreate Method.

    int SDK_INT = android.os.Build.VERSION.SDK_INT;
    
    if (SDK_INT>8){
    
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    
    StrictMode.setThreadPolicy(policy); 
    
    }
    

    Note: Disable the warning as you are already checking which version of the Android is going to use this code.

    This Code will be activated if the Android version is higher than Android 2.2

提交回复
热议问题