android 获取手机SD卡和手机的内部存储
来源:互联网 发布:淘宝上怎么收藏店铺 编辑:程序博客网 时间:2024/06/10 00:23
在开发过程中有时候会获取手机的SD存储使用状况。
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/memory" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center"/></LinearLayout>实现类
package com.example.phonememorystate;import java.io.File;import java.text.Format;import android.app.Activity;import android.os.Bundle;import android.os.Environment;import android.os.StatFs;import android.text.format.Formatter;import android.widget.TextView;public class MainActivity extends Activity {private TextView memoryInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); memoryInfo = (TextView) findViewById(R.id.memory); //外部存储的地址 File SDPath = Environment.getExternalStorageDirectory(); String SDMemory = getMemoryInfo(SDPath); //手机内部存储的地址 File PhonePath = Environment.getDataDirectory(); String PhoneMemory = getMemoryInfo(PhonePath); memoryInfo.setText("SD卡:" + SDMemory + "\n手机内存:" + PhoneMemory); } private String getMemoryInfo(File path){ //获取一个磁盘的状态对象 StatFs stat = new StatFs(path.getPath()); //获得一个扇区的大小 long blockSizes = stat.getBlockSize(); //获取扇区总数 long totalBlocks = stat.getBlockCount(); //获得可用扇区数量 long availableBlocks = stat.getAvailableBlocks(); //获得总空间 String totalMemory = Formatter.formatFileSize(this, blockSizes * totalBlocks); //获得可用空间 String availableMemory = Formatter.formatFileSize(this, availableBlocks * blockSizes); return "总空间:" + totalMemory + "\n可用空间" + availableMemory; }}
0 0
- android 获取手机SD卡和手机的内部存储
- Android获取手机和SD卡的存储存储信息
- Android获取不同手机 自身存储和外置SD卡存储路径的解决方案
- Android ndk获取手机内部存储卡的根目录
- Android获取手机内部存储和外部存储
- Android 漫游之路------将文件保存到内存、SD以及获取手机内部存储与外部存储空间的大小
- 获取Android手机中SD卡存储信息
- Android手机自带内部存储路径的获取
- Android手机自带内部存储路径的获取
- 手机SD卡的获取
- 将文件保存到内存、SD以及获取手机内部存储与外部存储空间的大小
- android 获取内部存储方式和sd卡状态
- Android判断是否存在外置SD卡(获取手机所有存储设备的路径)
- android 手机内置,sd卡存储的存储路径和空间问题
- android 扫描手机内存和SD卡,获取手机的视频、音频文件。把获取不到的文件扫描出来
- android 获取手机和SD卡可用内存
- android获取手机和sd卡上音乐列表
- Android--手机外部SD卡存储
- hdu1180 诡异的楼梯
- HDU 2177 取(2堆)石子游戏 Wythoff Game 求第一步方案
- 利用Scala语言开发Spark应用程序
- 兔子--动态设置控件的宽高
- 条款03:尽可能使用const
- android 获取手机SD卡和手机的内部存储
- LVS学习笔记 3LVS-DR实验 初步试验
- Javascript学习
- 修改ubuntu系统的时间
- Freertos 互斥锁
- 【c++】实现运算符的重载
- 【contentprovider系列7】自定义contentprovider
- Retrofit的使用教程(一)
- Linux 脱机管理问题