Code example for StrictMode.ThreadPolicy.Builder

Methods: build, detectNetwork

0
	 
	@TargetApi(11) 
	public static void beginLegacySection() { 
		if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) return; 
		originalPolicy = StrictMode.getThreadPolicy();
		Builder builder = new Builder();
		builder.detectNetwork()
		 .penaltyFlashScreen()
		 .penaltyLog();
		StrictMode.setThreadPolicy(builder.build());
	} 
	 
	@TargetApi(11) 
	public static void endLegacySection() { 
		if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB) return; 
		if (originalPolicy != null) StrictMode.setThreadPolicy(originalPolicy);
		originalPolicy = null;
	} 
}