i need convert the byte in Megabyte in my application but something is wrong.. First of all, i need display for example 1.2MB and not 1MB.. now, i have this declaration:
public long mStartRX = 0;
then in the onCreate
mStartRX = TrafficStats.getTotalRxBytes();
finally this to find the data usage in byte:
final long rxBytes = TrafficStats.getTotalRxBytes()- mStartRX;
RX.setText(Long.toString(rxBytes) + " " + "Bytes");
i tryied this solution:
final long rxBytes = TrafficStats.getTotalRxBytes()/(1024*1024)- mStartRX;
RX.setText(Long.toString(rxBytes) + " " + "Bytes");
but the result is not correct.. Infact i display something like: -1258912654
and of course it's not correct. How can i solve the problem?