I have a method to get any app's size. But the problem is I always get .00 value after the decimal.
Suppose, an app's size is 3.44
So, if I call my method then it will return a value of 3.00 And, it is same for every application. If any app's size is less than 1 mb, then I get 0.00. Please help me. Here is my method
private String getAppsSize() {
File cApp;
DecimalFormat cDFormat = new DecimalFormat("#.##");
double appSizeInMegaBytes;
String formattedText = null;
try {
cAInfo = cPManager.getApplicationInfo(getCurrentAppPackageName(), 0);
cApp = new File(cAInfo.publicSourceDir);
appSizeInMegaBytes = cApp.length() / 1048576;
cDFormat.format(appSizeInMegaBytes);
formattedText = Double.toString(appSizeInMegaBytes);
}
catch (PackageManager.NameNotFoundException e) {
showToast("Failed to count app size!");
e.printStackTrace();
}
return formattedText;
}
Here, I have a method getCurrentPackageName(). It causes no error. Because I am using it somewhere else. It works fine. So, now I don't know where my problem occurs...