【WD】IAPP实用代码大全[第一期]

IAPP   © 文章版权由 admin 解释,禁止匿名转载

#楼主# 2021-11-20

建议开始楼主模式观看

那废话不多说

评论区见

[真棒]
【WD】原创

第一个
字符串匹配网址
string.gmatchUrl=function(str)
local t={}
for i,v in string.gfind(str,"https?://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]") do
table.insert(t,string.sub(str,i,v))
end
return t
end--返回table,支持匹配多个链接

--调用示例
local str="Lua 官网 http://lua.org 安卓开发者 https://developer.android.google.cn/"
print(dump(str:gmatchUrl()))
第二个
dp,sp与px的转换
local scale=activity.getResources().getDisplayMetrics().scaledDensity

local function dp2px(dpValue)
return dpValue * scale + 0.5
end

local function px2dp(pxValue)
return pxValue / scale + 0.5
end

local function px2sp(pxValue)
return pxValue / scale + 0.5
end

local function sp2px(spValue)
return spValue * scale + 0.5
end
第三个
获取IMEI,IMSI,运营商名称
import "android.content.Context"
local telephone=activity.getSystemService(Context.TELEPHONY_SERVICE)

local IMEI=telephone.getDeviceId()
local IMSI=telephone.getSubscriberId()
local NetworkOperator=telephone.getNetworkOperatorName()
第四个
通知图库更新文件
--方法1 通过广播
activity.sendBroadcast(Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,Uri.parse("file://"..图片路径)))

--方法2 MediaScannerConnection
import "android.media.MediaScannerConnection"
MediaScannerConnection.scanFile(activity, {File(图片路径).getAbsolutePath()}, nil, nil)
第五个
遍历字符串
local a="你好, world!"

for i=1 , utf8.len(a) do
print(utf8.sub(a,i,i))
end

评论

登录后才可发表内容
  • 主题

    863

  • 帖子

    39585

  • 关注者

    0

Copyright © 2019 凯特网.   Powered by HYBBS 2.3.4  

Runtime:0.0467s Mem:2033Kb