Welcome Guest ( Log In | Register )

欢迎访问本站。游客仅能浏览首页新闻、版块主题、维基条目与资源信息,需登录后方可获得内容发布、话题讨论、维基编辑与资源下载等权限。若无账号请先完成注册流程。
 
Reply to this topicStart new topic
> Lua入门:实例二, Android手机发送短信给10001查询网络流量
bx_bob
2011-08-11, 11:52
Post #1


比非主流还非主流的Lua原教旨主义机械师
Group Icon
 817
   15

Group: Avatar
Posts: 416
Joined: 2007-07-25
Member No.: 14794


CODE
require "android"
android.smsSend("10001","108")
android.dialogCreateAlert("流量查询","已经发送短信,待收到回复后点击继续")
android.dialogSetPositiveButtonText("继续")
android.dialogShow()
android.dialogGetResponse()

all_sms=android.smsGetMessages(true)
--print("test")
sms_list=all_sms.result
--print(sms_list)
useful_sms_ids={}
for i = 1,#sms_list do
    --print (sms_list[i].address=="10001")
    if sms_list[i].address=="10001" then table.insert(useful_sms_ids,sms_list[i]) end
end

final_sms_list={}
for i=1,#useful_sms_ids do
    num=tonumber(string.match(useful_sms_ids[i].body,"^(%d)/%d%)"))
    final_sms_list[num]=useful_sms_ids[i].body
end

fulltext=""

for i,j in pairs(final_sms_list) do
    fulltext=fulltext..string.match(j,"^%d/%d%)(.-)$")
end

web_flow=string.match(fulltext,".*(已使用.-MB字节,剩余.-MB字节).*")
web_flow_now,web_flow_left=string.match(fulltext,".*已使用(.-)MB字节,剩余(.-)MB字节")

--print(web_flow,web_flow_now,web_flow_left)
android.dialogCreateHorizontalProgress("流量查询",web_flow,math.ceil(tonumber(web_flow_now+web_flow_left)))

android.dialogShow()
android.dialogSetCurrentProgress(math.ceil(tonumber(web_flow_now)))

Attached Image

This post has been edited by bx_bob: 2011-08-11, 12:01
TOP
Fast ReplyReply to this topicStart new topic
 


Time is now: 2021-09-17, 23:51