Tag Archives: Android

How to disable pop-up / preview (heads up) message notifications for Samsung Galaxy S7, S8 and S8+

To disable heads-up notifications, install Android SDK and issue the following command in command line (all in one line):
adb shell settings put global heads_up_notifications_enabled 0

To simply view current settings before or after changes, use:
adb shell settings get global heads_up_notifications_enabled

More ways on how to disable these settings (if not available via user interface) is located at xda-developers site.

P.S. This works on Samsung Galaxy S7 edge with Android 7.0 and Galaxy S8+ Android 7.0.

Android devices sometimes use wrong DNS server

Android devices sometimes use wrong DNS server. My assumption is, that it happens when device finds friendly WiFi access point, disconnects from mobile provider/ISP and is just finished connecting to it (WiFi using DHCP). It has setup DNS servers from WiFi, however, it still sends requests to DNS from mobile ISP via WiFi network.
It seems that some caching is going on, and it feels wrong… because mobile ISP may be blocking DNS requests from other networks.

Tested on Galaxy Tab 8.9″ with Android 3.2 and Galaxy Note 10.1″ with Android 4.0.4.

String.format in Java has weird rounding by default

I was participating in one of our Android projects, and while testing I discovered, that our program acted weird — app displayed one value, but acted like the value was different. The value was 1.45, and our Java Android app displayed 1.4 instead of 1.5.

The source looked something like:
double d = 1.45;
String val = String.format(Locale.US, "%.1f", d) + "%";

I am still a beginner in Java, and at first I believed, that String.format rounds down by default. This was till I saw, that value 1.55 is rounded up by default.

Digging into Java documentation I found, that String.format uses RoundingMode HALF_EVEN by default:

Rounding mode to round towards the “nearest neighbor” unless both neighbors are equidistant, in which case, round towards the even neighbor. Behaves as for RoundingMode.HALF_UP if the digit to the left of the discarded fraction is odd; behaves as for RoundingMode.HALF_DOWN if it’s even. Note that this is the rounding mode that statistically minimizes cumulative error when applied repeatedly over a sequence of calculations. It is sometimes known as “Banker’s rounding,” and is chiefly used in the USA. This rounding mode is analogous to the rounding policy used for float and double arithmetic in Java.

http://docs.oracle.com/javase/6/docs/api/java/math/RoundingMode.html

Of course other beginners are also discovering this Java Rounding.

Unfortunately Android does not support setRoundingMode, so currently using the following workaround:
double d = (double)Math.round(((double)percents) * 10f) / 10f;
String val = String.format(Locale.US, "%.1f", d) + "%";