位置: 编程技术 - 正文

获取Android设备挂载的所有存储器(android获取本机ip地址)

发布时间:2024-02-27

推荐整理分享获取Android设备挂载的所有存储器(android获取本机ip地址),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:安卓怎么获取设备id,安卓怎么获取设备id,获取android设备唯一标识码,android获取手机的基本信息,android获取手机的基本信息,获取android_id,android10获取设备id,android获取设备信息,内容如对您有帮助,希望把文章链接给更多的朋友!

转自: StorageVolume[] getVolumeList() { if (mMountService == null) return new StorageVolume[0]; try { Parcelable[] list = mMountService.getVolumeList(); if (list == null) return new StorageVolume[0]; int length = list.length; StorageVolume[] result = new StorageVolume[length]; for (int i = 0; i < length; i++) { result[i] = (StorageVolume)list[i]; } return result; } catch (RemoteException e) { Log.e(TAG, "Failed to get volume list", e); return null; } }

通过反射,获取到Android设备所有存储器。publicclassStorageInfo{publicStringpath;publicStringstate;publicbooleanisRemoveable; publicStorageInfo(Stringpath){this.path=path;} publicbooleanisMounted(){return"mounted".equals(state);}} public static List<StorageInfo> listAvaliableStorage(Context context) { ArrayList<StorageInfo> storagges = new ArrayList<StorageInfo>(); StorageManager storageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE); try { Class<?>[] paramClasses = {}; Method getVolumeList = StorageManager.class.getMethod("getVolumeList", paramClasses); getVolumeList.setAccessible(true); Object[] params = {}; Object[] invokes = (Object[]) getVolumeList.invoke(storageManager, params); if (invokes != null) { StorageInfo info = null; for (int i = 0; i < invokes.length; i++) { Object obj = invokes[i]; Method getPath = obj.getClass().getMethod("getPath", new Class[0]); String path = (String) getPath.invoke(obj, new Object[0]); info = new StorageInfo(path); File file = new File(info.path); if ((file.exists()) && (file.isDirectory()) && (file.canWrite())) { Method isRemovable = obj.getClass().getMethod("isRemovable", new Class[0]); String state = null; try { Method getVolumeState = StorageManager.class.getMethod("getVolumeState", String.class); state = (String) getVolumeState.invoke(storageManager, info.path); info.state = state; } catch (Exception e) { e.printStackTrace(); } if (info.isMounted()) { info.isRemoveable = ((Boolean) isRemovable.invoke(obj, new Object[0])).booleanValue(); storagges.add(info); } } } } } catch (NoSuchMethodException e1) { e1.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } storagges.trimToSize(); return storagges; }获取Android设备挂载的所有存储器(android获取本机ip地址)

如何判断存储器是内置存储还是外置存储呢?StorageVolume这个类中提供了一个isRemovable()接口,通过反射调用它就可以知道存储器是否可以移除。把可以移除的存储器认定为外置sdcard,不可移除的存储器认定为内置存储器。1MethodisRemovable=obj.getClass().getMethod("isRemovable",newClass[0]);

如何判断存储器的挂载状态呢?同上面一样,需要反射系统接口才可以获取到挂载状态。下面是代码片段MethodgetVolumeState=StorageManager.class.getMethod("getVolumeState",String.class); state=(String)getVolumeState.invoke(storageManager,info.path); info.state=state;

总结通过反射系统的StorageManager以及StorageVolume类提供的接口,就可以拿到Android设备挂载的所有存储器路径,以及存储器类型(内置存储还是外置存储),还有存储器的挂载状态等信息。

Android------Toast的使用 原本以为Toast只有那么一个简单的功能,就是Toast.makeText(context,text,duration).show();这样就完了。但是前几天发现一个问题就是不能在子线程中这么用,于是

android 事件处理机制之requestDisallowInterceptTouchEvent 原blog地址:

不用改变软输入法的位置 ?xmlversion=1.0encoding=utf-8?LinearLayoutxmlns:android=

标签: android获取本机ip地址

本文链接地址:https://www.jiuchutong.com/biancheng/382199.html 转载请保留说明!

上一篇:【正途】Android R.java文件丢失的问题(正途科技有限公司)

下一篇:Android---59---Toast的使用

  • 工会经费的计税依据是含税还是不含税
  • 增值税专用发票有效期是多长时间
  • 企业所得税申报时间
  • 所有者权益是
  • 合伙人没有账目就说赔了合法吗
  • 一般纳税人需要申报什么税
  • 房产税收取标准有哪些
  • 押金可以抵扣吗
  • 公司比赛规则
  • 其他应收款 应收账款
  • 付出的房屋押金可以退吗
  • 预收账款发货
  • 企业以前年度的关联交易与预约定价安排
  • 以前年度留抵用完 不能抵欠税
  • 公司不动产管理办法
  • 销售方开票不填开户行
  • 出纳人员怎么进入会计
  • 固定资产转入清理记账凭证
  • 苹果手机zm
  • 固定资产无偿转让程序是什么
  • deepin下载教程
  • php的注释可以使用什么开头
  • nmstt.exe - nmstt是什么进程 有什么用
  • 工程施工暂估成本的账务处理流程
  • 系统win7旗舰版
  • php教程全集
  • 出差海外
  • 内账怎么处理增值税
  • bootstrap步骤
  • php的strcmp
  • 固定资产修理支出准予扣除吗
  • 厂房维修费是制造费用还是管理费用
  • 餐厅手撕发票
  • function函数的定义
  • 增值税减免怎么填写
  • 贷款减值准备怎么进损益类账户
  • 什么是电子税务局app
  • 填写发票票种核实怎么填
  • 个人所得税大病医疗夫妻双方怎么扣除
  • 织梦小说采集
  • 帝国cms到底好不好
  • 企业自产自用产品要确认收入吗
  • 开具利息收入发票需不需要有经营范围
  • 还有什么服务啊
  • 银行代发工资流程
  • sql脚本语言怎么写
  • mysql忘了密码
  • 固定资产加速折旧最新税收政策2023
  • 公对公转账货款是指往来款吗
  • 个体户需要实缴吗
  • 增值税普票没有发票章可以吗
  • 企业将购进的原材料分录
  • 将购进药品销售给药品生产企业或药品经营企业的是
  • 代金券的利弊有哪些方面
  • 个人承担社保如何办理
  • 企业里面不征税的有哪些
  • 支票有效期过期了怎么办
  • 公司的私账
  • sql需要哪些基础
  • Windows 10 与 MySQL 5.5 安装使用及免安装使用详细教程(图文)
  • windows server2008系统弹出今天必须修改密码该怎么处理?
  • 64位win7旗舰版右下角音量小喇叭图标不见了怎么找回?
  • xp系统内存不足怎么办
  • ubuntu每次开机都会进入grub
  • centos哪个版本最好用2022
  • win8设置宽带连接
  • js domcontentloaded
  • android textview设置字体
  • python怎么输出日志
  • 插入排序_Python与PHP的实现版(推荐)
  • 我决定放弃了你却对我笑了
  • easyui原理
  • js正则 \w
  • 安卓中的菜单
  • python 技巧
  • 电商平台税收怎么交
  • 长沙税务局几点上班下午
  • 授课费800元个税要收吗
  • 深圳税务忘记密码
  • 甘肃省国家励志奖学金证书打印网址
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号