I am working on Network based project in android, so, to prevent force close on Android ICS because of Can't do network operation on UI Thread , I must use the part of code such below or try to start my network operation on other thread, but I don’t want to change the base code, so I should use the code as below on Android ICS. :
static {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
How can I make unique apk file to run in all android version ( >= 1.6 ) ? android.os.StrictMode is accessible for higher version of android, so, i can not try to use the above part of code in my Android Activity. So, which solution is better :
- Using Reflections to run this part of code on higher versions of API (
As oracle docs, reflective operations have slower performance than their non-reflective counterparts) - Change my android build target to Android 4.1.1 (API 16) and try to change the
android:minSdkVersionon AndroidManifest.xml
Or if you know any better ones, please let me know.
Thanks in advance 🙂
You can use BUILD.VERSION and reflection to get over this compability problem (tested).