一、最终效果
远程开机app下载:
下载链接:https://wwp.lanzoup.com/iDR330ml4l2b
提取码 : dxcg
注意:使用前请按照2.1的步骤设置电脑“
mac地址:填写自己的mac地址
主机地址:填写自己的公网ip,百度搜索ip
映射端口:第二点准备工作里面配置的映射端口

二、准备工作
2.1. 开启bios的wol远程唤醒功能
主板品牌启动按键Intel主板F12昂达主板F11顶星主板F11或F12富士康主板ESC或F12冠盟主板F11或F12冠铭主板F9华擎主板F11华硕主板F8技嘉主板F12杰微主板ESC或F8捷波主板ESC精英主板ESC或F11梅捷主板E5C或F12铭瑄主板ESC譬正主板ESC七彩虹主板ESC或F11双敏主板ESC斯巴达卡主板ESC微星主板F11翔升主板F10盈通主板F8映奏主板F9致铭主板F12智英主板ESC常见笔记本品牌
笔记本品牌启动按键eMachines笔记本F12Gateway笔记本F12IBM笔记本F12东芝笔记本F12方正笔记本F12海尔笔记本F12宏基笔记本F12华硕笔记本ESC患晋笔记本F9技嘉笔记本F12截尔笔记本F12联想ThinkpadF12联想笔记本F12明基笔记本F9苹果笔记本长按"option"键清华同方笔记本F12三星笔记本F12神舟笔记本F12室士通笔记本F12素尼笔记本ESC微星笔记本F11
台式机品牌启动按键方正台式机F12海尔台式机F12宏基台式机F12华硕台式机F8惠昔台式机F12截尔台式机ESC联想台式机F12明基台式机F8清华同方台式机F12神舟台式机F12注意:其他品牌请百度或尝试以上按键
进入BIOS后找一下有没有Wake On LAN 、远程唤醒、WOL等相关字样的选项,找到并启用。
如果还不知如何设置,百度搜索”主板型号+远程唤醒“
TP Link路由器设置如下,其余路由器设置类似,请自行百度。

注意内网IP与电脑的IP一致,就是刚才MAC绑定时的IP地址,端口任意选择,协议类型选择ALL或者UDP。

点击”此电脑->设备管理器->网络适配器",启用唤醒魔包。

2.2. 下载Andlua+软件
软件下载链接,关注【产品经理不是经理】gzh,回复【andlua+】即可下载。
三、实现代码
3.1. 打开软件,新建项目,创建步骤如下:


- 填写项目名称和包名。项目名称随便填,包名类似com.xx.xx,随意填写就行。


3.2. 编写代码:
- require "import"
- import "android.app.*"
- import "android.os.*"
- import "android.widget.*"
- import "android.view.*"
- import "layout"
- import "socket"
- activity.setTheme(R.Theme_Blue)
- activity.setTitle("远程开机")
- activity.setContentView(loadlayout(layout))
- -- 将两个一组字符串表示的十六进制转为十六进制的字符串
- -- 'ff'(66 66) -> 0xff -> '.'(255)
- function to(str)
- ret = ''
- for i = 1, string.len(str), 2 do
- byte = ('0x' .. string.sub(str, 0 + i, 1 + i))
- a = tonumber(byte)
- ret = ret .. string.char(a)
- end
- return ret
- end
- function wakeUp(mac,bip,port)
- -- 要进行目标主机的MAC地址
- -- 路由器广播地址
- -- 映射端口
- mac=string.gsub(mac,":","")
- head = 'FFFFFFFFFFFF' -- 数据头
- head = to(head)
- mac = to(mac)
- for i = 1, 16 do
- head = head .. mac
- end
- u = socket.udp()
- u:sendto(head,bip,port)
- u:close()
- toast("魔术包发送成功")
- end
- -- 判断是否为空
- function isEmpty(s)
- local flag=false
- if s==nil or s=="" then
- flag=true
- end
- return flag
- end
- -- 自定义toast
- function toast(msg,activity,duration)
- local activity=activity or this
- local msg=msg or ""
- local duration=duration or Toast.LENGTH_SHORT
- Toast.makeText(activity, msg,duration).show()
- end
- btn.onClick=function()
- mac=tostring(macAddr.getText())
- host1=tostring(host.getText())
- port1=tostring(port.getText())
- if isEmpty(mac) or isEmpty(host1) or isEmpty(port1) then
- toast("mac地址、主机地址、端口均不能为空")
- return
- end
- wakeUp(mac,host1,port1)
- end
复制代码- {
- LinearLayout;
- orientation="vertical";
- layout_height="wrap_content";
- layout_width="match_parent";
- backgroundColor="0xffc4d7d6";
- {
- LinearLayout;
- layout_marginTop="20dp";
- layout_width="match_parent";
- {
- TextView;
- textSize="16sp";
- layout_marginLeft="10dp";
- layout_width="wrap_content";
- layout_height="wrap_content";
- textColor="0xff000000";
- text="mac地址:";
- };
- {
- EditText;
- text="04:7C:16:01:21:85";
- layout_width="match_parent";
- id="macAddr";
- layout_marginRight="10dp";
- };
- };
- {
- LinearLayout;
- layout_width="match_parent";
- layout_height="wrap_content";
- {
- TextView;
- textSize="16sp";
- textColor="0xff000000";
- layout_marginLeft="10dp";
- text="主机地址:";
- };
- {
- EditText;
- text="123.145.8.199";
- layout_width="match_parent";
- id="host";
- layout_marginRight="10dp";
- };
- };
- {
- LinearLayout;
- layout_width="match_parent";
- {
- TextView;
- textSize="16sp";
- textColor="0xff000000";
- layout_marginLeft="10dp";
- text="映射端口:";
- };
- {
- EditText;
- layout_marginRight="10dp";
- layout_width="match_parent";
- id="port";
- text="9";
- };
- };
- {
- Button;
- layout_marginLeft="15dp";
- id="btn";
- text="一键开机";
- layout_marginTop="20dp";
- backgroundColor="0xff10aec2";
- textColor="0xffffffff";
- layout_height="wrap_content";
- layout_width="match_parent";
- layout_marginRight="15dp";
- };
- };
复制代码
- init.lua使用模板代码,不做更改。
- 修改完成后,点击三角符号预览

3.2. 打包app:
取消选中调试模式,app需要的权限我们只选择拥有完全的网络访问权限即可,设置完成后点击右上角的勾保存。


三、总结
andlua+软件提供了丰富的功能,让我们在手机上可以编程快速生成我们自己的应用,更多复杂的应用需要大家自行探索。
本文由【产品经理不是经理】gzh同步发布,欢迎关注
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |