花粉乐分享平台宣传视频
> 华为资讯 > 华为资讯 > 鸿蒙编程 > 鸿蒙(Harmony)开发手机管家APP示例
鸿蒙(Harmony)开发手机管家APP示例
来源:DevEcoStudio
2022-12-02 22:41:05
337
管理

一、设计布局文件

二、打开MainAbilitySlice.java文件并录入以下关键代码

打开MainAbilitySlice.java

import ohos.aafwk.ability.AbilitySlice;import ohos.aafwk.ability.DeviceConfigInfo;import ohos.aafwk.ability.RunningProcessInfo;import ohos.aafwk.ability.SystemMemoryInfo;import ohos.aafwk.content.Intent;import ohos.agp.components.Button;import ohos.agp.components.Component;import ohos.agp.components.Text;import ohos.agp.utils.LayoutAlignment;import ohos.app.IAbilityManager;import ohos.app.dispatcher.TaskDispatcher;import ohos.hiviewdfx.HiLog;import ohos.hiviewdfx.HiLogLabel;import java.util.List;public class MainAbilitySlice extends AbilitySlice { private static final HiLogLabel hiLogLabel = new HiLogLabel(HiLog.LOG_APP, 0x00888, "BingJunNetWorkLog"); Text ShowMemoryInfo=null; SystemMemoryInfo systemMemoryInfo =null; IAbilityManager iAbilityManager =null; List runningProcessInfos=null; DeviceConfigInfo deviceConfigInfo=null; @Override public void onStart(Intent intent) { super.onStart(intent); super.setUIContent(ResourceTable.Layout_ability_main); Button CheckMemory=(Button) findComponentById(ResourceTable.Id_CheckMemory); ShowMemoryInfo=(Text) findComponentById(ResourceTable.Id_ShowMemoryInfo); CheckMemory.setClickedListener(clickedListener); Button ClearMemory=(Button) findComponentById(ResourceTable.Id_ClearMemory); ClearMemory.setClickedListener(clickedListener); } public Component.ClickedListener clickedListener= component -> { switch (component.getId()){ case ResourceTable.Id_CheckMemory: ShowMemoryInfo.setText(""); this.GetSystemMemoryInfo(); break; case ResourceTable.Id_ClearMemory: ShowMemoryInfo.setText(""); this.ClearMemoryAndKillProcesses(); this.LoadSampleToast("内存清理完毕",0,0,2000, LayoutAlignment.CENTER); this.GetSystemMemoryInfo(); break; default: break; } }; public void GetSystemMemoryInfo(){ TaskDispatcher taskDispatcher=this.getUITaskDispatcher(); taskDispatcher.asyncDispatch(() -> { try { systemMemoryInfo = new SystemMemoryInfo(); iAbilityManager = getAbilityManager(); iAbilityManager.getSystemMemoryInfo(systemMemoryInfo); ShowMemoryInfo.append("总系统内存大小:" systemMemoryInfo.getTotalSysMem() "rn"); ShowMemoryInfo.append("可用系统内存大小:" systemMemoryInfo.getAvailSysMem() "rn"); ShowMemoryInfo.append("可用系统内存的阈值:" systemMemoryInfo.getThreshold() "rn"); if (systemMemoryInfo.isLowSysMemory()==true){ ShowMemoryInfo.append("内存不足rn"); }else { ShowMemoryInfo.append("内存充足rn"); } if (iAbilityManager.isLowRamDevice()==true){ ShowMemoryInfo.append("低RAM设备rn"); }else { ShowMemoryInfo.append("高RAM设备rn"); } ShowMemoryInfo.append("基本内存大小:" IAbilityManager.DEFAULT_HEAPSIZE "rn"); ShowMemoryInfo.append("默认密度:" IAbilityManager.DEFAULT_DENSITY "rn"); ShowMemoryInfo.append("主屏幕上图标的密度:" iAbilityManager.getHomeScreenIconDensity() "rn"); ShowMemoryInfo.append("默认图标大小:" IAbilityManager.DEFAULT_ICONSIZE "rn"); ShowMemoryInfo.append("主屏幕上图标的大小:" iAbilityManager.getHomeScreenIconSize() "rn"); ShowMemoryInfo.append("应用程序可以使用的最大内存:" iAbilityManager.getAppLargeMemory() "rn"); ShowMemoryInfo.append("应用程序可以使用的内存:" iAbilityManager.getAppMemory() "rn"); deviceConfigInfo=iAbilityManager.getDeviceConfigInfo(); ShowMemoryInfo.append("所需的OpenGL ES版本:" deviceConfigInfo.getDeviceGLESVersion() "rn"); if (deviceConfigInfo.getExternalInputDevices()==0){ ShowMemoryInfo.append("不需要外部输入设备:rn"); }else if (deviceConfigInfo.getExternalInputDevices()==1){ ShowMemoryInfo.append("需要外部物理键盘rn"); } else { ShowMemoryInfo.append("需要外部五向(上,下,右,左和选择)导航设备rn"); } if (deviceConfigInfo.getKeyBoardType()==0){ ShowMemoryInfo.append("不需要键盘rn"); }else if (deviceConfigInfo.getKeyBoardType()==1){ ShowMemoryInfo.append("需要具有QWERTY布局的键盘rn"); }else { ShowMemoryInfo.append("需要具有12键布局的键盘rn"); } if (deviceConfigInfo.getNavigationType()==0){ ShowMemoryInfo.append("不需要导航设备rn"); }else if (deviceConfigInfo.getNavigationType()==1){ ShowMemoryInfo.append("所需的导航设备:方向键rn"); }else if (deviceConfigInfo.getNavigationType()==2){ ShowMemoryInfo.append("所需的导航设备:跟踪球rn"); }else { ShowMemoryInfo.append("所需的导航设备:滚轮rn"); } if (deviceConfigInfo.getTouchScreenType()==0){ ShowMemoryInfo.append("不需要触摸屏rn"); }else { ShowMemoryInfo.append("需要可以用指尖操作的触摸屏rn"); } /*runningProcessInfos=iAbilityManager.getAllRunningProcesses(); for (int i=0; i { try { //iAbilityManager.clearUpApplicationData(); //清除应用程序的用户数据,这相当于初始化应用程序。 //此方法删除与该应用程序相关的所有动态数据和通知 //并撤消用户已授予它的所有权限,但不删除其核心文件。使用此方法时请多加注意。 runningProcessInfos=iAbilityManager.getAllRunningProcesses(); for (int i=0; i { ToastSample toastSample=new ToastSample(); toastSample.SampleToast(this,ToastText, alignment,x,y,ms); }); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); }}

三、编译项目并运行应用程序

运行模拟器

运行效果

运行效果

运行效果

四、感谢您的观看[微笑],不足之处敬请批评指正,期待您的关注与收藏,您的关注与转发就是我的动力,下期您会收到更精彩的文章,谢谢!

花粉社群VIP加油站

1
点赞
赏礼
赏钱
0
收藏
免责声明:本文仅代表作者个人观点,与花粉乐分享无关。其原创性以及文中陈述文字和内容未经本网证实,对本文以及其中全部或者 部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
凡本网注明 “来源:XXX(非花粉乐分享)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对 其真实性负责。
如因作品内容、版权和其它问题需要同本网联系的,请在一周内进行,以便我们及时处理。
QQ:2443165046 邮箱:info@hflfx.com
关于作者
理想青年(采蜜高手)
文章
456
主题
0
关注
0
粉丝
0
点击领取今天的签到奖励!
签到排行
随手拍
54个圈友 0个话题
华为手机随手拍,记录生活点滴之美好
华为P30pro
51个圈友 0个话题
这里是华为P30pro手机交流圈,欢迎华为P30pro用户进群交流
体验官
60个圈友 2个话题
华为花粉体验官,体验官专属的交流群
登录后查看您创建的圈子
登录后查看您创建的圈子
所有圈子
杭州互联网违法和不良信息举报平台 网络110报警服务 浙ICP备17046585号
1
0
分享
请选择要切换的马甲:

个人中心

每日签到

我的消息

内容搜索