读取SD卡的容量的时候出错了。怎么回事?

suhaihui 2014-07-20 08:48:04


LOGCAT如上。

程序如下:

public static class PlaceholderFragment extends Fragment {

public PlaceholderFragment() {
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
TextView sizeTextView=(TextView) rootView.findViewById(R.id.allsize);
sizeTextView.setText("SD卡总大小:"+getSDTotalSize());
return rootView;
}

/**
* 获得SD卡总大小
*
* @return
*/
private String getSDTotalSize() {
File path = Environment.getExternalStorageDirectory();
StatFs stat = new StatFs(path.getPath());
long blockSize = stat.getBlockSizeLong();
long totalBlocks = stat.getBlockCountLong();
return Formatter.formatFileSize(this.getActivity(),blockSize*totalBlocks);
}
}

为何会提示没有getBlockSizeLong(); 函数?不明白!
...全文
494 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
mybeta 2014-07-21
  • 打赏
  • 举报
回复
引用 7 楼 suhaihui 的回复:
[quote=引用 6 楼 mybeta 的回复:] getBlockSizeLong () Added in API level 18 请使用 getBlockSize ()
请看!这是我为什么不用 getBlockSize ()的原因 [/quote] 因为。。。你的target sdk设置的大于等于18,而min sdk设置的小于18,只要min sdk小于18,你就不能使用18中添加 的方法,至于你这里提示过期是正常的,这只是在API 18中过期,即使过期,照样正常使用
哎,真难 2014-07-21
  • 打赏
  • 举报
回复
那就不知道了,你看下android自带的jar包里面是不是没有找到android.os.StatFs;
mybeta 2014-07-21
  • 打赏
  • 举报
回复
getBlockSizeLong () Added in API level 18 请使用 getBlockSize ()
suhaihui 2014-07-21
  • 打赏
  • 举报
回复
引用 5 楼 heaimnmn 的回复:
目测没错误,看下getBlockSizeLong是调用哪里的方法
是StatFS里面的方法。
suhaihui 2014-07-21
  • 打赏
  • 举报
回复
引用 4 楼 u010129124 的回复:

/**
* The size, in bytes, of a block on the file system. This corresponds
* to the Unix statfs.f_bsize field.
*/
public native int getBlockSize();


用这个呢


为什么我的是这样?
suhaihui 2014-07-21
  • 打赏
  • 举报
回复
引用 6 楼 mybeta 的回复:
getBlockSizeLong () Added in API level 18
请使用 getBlockSize ()


请看!这是我为什么不用 getBlockSize ()的原因

哎,真难 2014-07-21
  • 打赏
  • 举报
回复
目测没错误,看下getBlockSizeLong是调用哪里的方法
青龙山之叶 2014-07-21
  • 打赏
  • 举报
回复

 /**
  * The size, in bytes, of a block on the file system.  This corresponds
  * to the Unix statfs.f_bsize field.
  */
    public native int getBlockSize();

用这个呢
fireyou 2014-07-21
  • 打赏
  • 举报
回复
已经显示错误了:NoSuchMethodError ... 没有方法。。
sagittarius1988 2014-07-21
  • 打赏
  • 举报
回复
你可以问提供系统的厂商要方法或者用反射看看StatFs下都有哪些接口方法
sagittarius1988 2014-07-21
  • 打赏
  • 举报
回复
系统被定制过了,没有getBlockSizeLong这个方法

80,349

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧