我想要Iternal存儲獲取內存和使用的內存在進度欄中像在我的app.how應用程序下面的圖像請幫助我在android.and中使用進度條我使用下載的應用程序。 如何在android中檢查內部存儲器數量?
0
A
回答
2
下面是它如何來完成:
TestActivity.java:
public class TestActivity extends Activity {
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView occupiedSpaceText = (TextView)findViewById(R.id.occupiedSpace);
final TextView freeSpaceText = (TextView)findViewById(R.id.freeSpace);
final ProgressBar progressIndicator = (ProgressBar)findViewById(R.id.indicator);
final float totalSpace = DeviceMemory.getInternalStorageSpace();
final float occupiedSpace = DeviceMemory.getInternalUsedSpace();
final float freeSpace = DeviceMemory.getInternalFreeSpace();
final DecimalFormat outputFormat = new DecimalFormat("#.##");
if (null != occupiedSpaceText) {
occupiedSpaceText.setText(outputFormat.format(occupiedSpace) + " MB");
}
if (null != freeSpaceText) {
freeSpaceText.setText(outputFormat.format(freeSpace) + " MB");
}
if (null != progressIndicator) {
progressIndicator.setMax((int) totalSpace);
progressIndicator.setProgress((int)occupiedSpace);
}
}
/**
* From question http://stackoverflow.com/questions/2652935/android-internal-phone-storage by Lazy Ninja
*/
public static class DeviceMemory {
public static float getInternalStorageSpace() {
StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
//StatFs statFs = new StatFs("/data");
float total = ((float)statFs.getBlockCount() * statFs.getBlockSize())/1048576;
return total;
}
public static float getInternalFreeSpace() {
StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
//StatFs statFs = new StatFs("/data");
float free = ((float)statFs.getAvailableBlocks() * statFs.getBlockSize())/1048576;
return free;
}
public static float getInternalUsedSpace() {
StatFs statFs = new StatFs(Environment.getDataDirectory().getAbsolutePath());
//StatFs statFs = new StatFs("/data");
float total = ((float)statFs.getBlockCount() * statFs.getBlockSize())/1048576;
float free = ((float)statFs.getAvailableBlocks() * statFs.getBlockSize())/1048576;
float busy = total - free;
return busy;
}
}
}
佈局/ main.xml中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:id="@+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
style="@android:style/Widget.ProgressBar.Horizontal"
android:progressDrawable="@drawable/memory_indicator_progress" />
<TextView
android:id="@+id/occupiedSpace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:gravity="left"
android:layout_marginLeft="5dp"
android:textColor="@android:color/black"
android:textStyle="bold" />
<TextView
android:id="@+id/freeSpace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:gravity="right"
android:layout_marginRight="5dp"
android:textColor="@android:color/black"
android:textStyle="bold" />
</RelativeLayout>
繪製/ memory_indicator_progress.xml:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<solid android:color="@android:color/holo_green_light" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape android:shape="rectangle">
<solid android:color="@android:color/darker_gray" />
</shape>
</clip>
</item>
</layer-list>
我不知道這是否正是你要找的,但我與4.1的Android手機XPERIA V I得到如下圖:
在您由於平臺不同,設備顏色可能會有所不同。
+0
感謝Sandrstar的回覆我會檢查它。 – crickpatel0024 2013-03-20 09:30:27
0
使用android.os.Environment查找內部目錄,然後使用android.os.StatFs調用它的Unix statfs系統調用。無恥地stolen從Android應用程序的設置:
File path = Environment.getDataDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSize();
long availableBlocks = stat.getAvailableBlocks();
return Formatter.formatFileSize(this, availableBlocks * blockSize);
+0
感謝您的回覆!!但如何在android.used內存顏色和可用內存顏色進度條中設置文本進度條如何可能請幫助我! – crickpatel0024 2013-03-20 07:48:30
相關問題
- 1. Android:如何在內部存儲器上存儲數據?
- 2. Android,如何將圖像存儲在內部存儲器中?
- 3. 訪問數據如何在Android中形成內部存儲器
- 4. Android:如何寫入內部存儲器
- 5. 試圖檢查內部存儲器中是否存在文件
- 6. Android:如何檢查剩餘內存量?
- 7. 如何使用存儲在內部數據存儲器中的圖像android
- 8. (Android)在內部存儲器中查找路徑/ Android
- 9. android內部存儲器
- 10. Android內部存儲器
- 11. 如何從內部存儲器拍照並將拍攝圖像保存在內部存儲器android中?
- 12. 內部存儲器中的存儲數據Android
- 13. 如何查看數據庫內電話內部存儲器
- 14. 如何存儲和讀取內部存儲器中的整數
- 15. Android在內部存儲器中保存數據NullPointerException
- 16. Android如何在內部存儲器中創建文件夾?
- 17. 在內部存儲器中查看創建的文件夾android
- 18. 無法在內部存儲器中存儲視頻文件Android
- 19. 在android內部存儲器中存儲圖像
- 20. android-在內部存儲器中存儲圖像
- 21. 如何檢查文件是否在內部存儲器中可用
- 22. 我如何將記錄的文件存儲在android的內部存儲器中?
- 23. 如何從Android的內部存儲中檢索位圖文件?
- 24. 外部和內部存儲如何同時檢查
- 25. 如何在MB中計算可用內部存儲器內存?
- 26. android內部存儲?
- 27. Android:在內部存儲數據
- 28. 如何將鍵值對存儲在將存儲在Android內部存儲器中的文件中?
- 29. hstore如何在內部存儲數據?
- 30. Javascript - 數組如何在內部存儲?
你有沒有嘗試通常的進度欄和兩個文本視圖對齊到不同的邊? – sandrstar 2013-03-20 07:58:44
是的,我想要2個textview裏面的進度條。 – crickpatel0024 2013-03-20 08:06:19