安裝apk
安裝APK(filePath)
- lua原始碼
function 安裝APK(filePath)
local intent = Intent(Intent.ACTION_VIEW);
intent.addCategory("android.intent.category.DEFAULT");
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
local uri = nil
if (Build.VERSION.SDK_INT >= 24) then--24是N
uri = xFileProvider.getUriForFile(activity, activity.getPackageName()..".FileProvider", File(filePath))
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
else
uri = Uri.fromFile(File(filePath))
end
intent.setDataAndType(uri, "application/vnd.android.package-archive");
activity.startActivity(intent);
end
聯系QQ(qqNUM)
聯系QQ(qqNUM)
- lua原始碼
function 聯系QQ(qqNUM)
local s = "mqqwpa://im/chat?chat_type=wpa&uin=" .. qqNUM
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(s)))
end
加QQ群
加QQ群
- lua原始碼
function 加QQ群(qqNUM)
local s = "mqqapi://card/show_pslcard?src_type=internal&version=1&uin=" .. qqNUM .. "&card_type=group&source=qrcode"
activity.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(s)))
end
發送郵件
發送郵件(email,subject,content)
- lua原始碼
function 發送郵件(email,subject,content)
import "android.content.Intent"
i = Intent(Intent.ACTION_SEND)
i.setType("message/rfc822")
i.putExtra(Intent.EXTRA_EMAIL, {email})
i.putExtra(Intent.EXTRA_SUBJECT,subject)
i.putExtra(Intent.EXTRA_TEXT,content)
activity.startActivity(Intent.createChooser(i, "Choice"))
end
獲取剪切板
獲取剪切板()
- lua原始碼
function 獲取剪切板()
if(Context==nil)then
import "android.content.Context"
end
return activity.getSystemService(Context.CLIPBOARD_SERVICE).getText()
end
復制文本
復制文本(a)
- lua原始碼
function 復制文本(a)
if(Context==nil)then
import "android.content.Context"
end
activity.getSystemService(Context.CLIPBOARD_SERVICE).setText(a)
end
分享鏈接
分享鏈接()
- lua原始碼
function 分享鏈接()
分享文本(獲取瀏覽器().url)
end
對話框
泡沫對話框
- lua原始碼
local bindClass=luajava.bindClass
local AlertDialog=bindClass("android.app.AlertDialog")
local Builder=AlertDialog.Builder
local indexBuilderPool={}
function 對話框(ctx)
local index=#indexBuilderPool+1
local dialog=AlertDialog.Builder(ctx or activity or this)
indexBuilderPool[index]=dialog
local _M
_M= {
["設定標題"]=function(...) dialog.setTitle(...) return _M end;
["設定訊息"]=function(...) dialog.setMessage(...) return _M end;
["設定積極按鈕"]=function(...)
local args={...}
if (#args==1) then
dialog.setPositiveButton(args[1],nil)
else
dialog.setPositiveButton(...)
end
return _M end;
["設定消極按鈕"]=function(...)
local args={...}
if (#args==1) then
dialog.setNegativeButton(args[1],nil)
else
dialog.setNegativeButton(...)
end
return _M end;
["設定中立按鈕"]=function(...)
local args={...}
if (#args==1) then
dialog.setNeutralButton(args[1],nil)
else
dialog.setNeutralButton(...)
end
return _M end;
["顯示"]=function(...)
dialog=dialog.show(...)
indexBuilderPool[index]=dialog
return _M end;
["創建"]=function(...)
dialog=dialog.create(...)
indexBuilderPool[index]=dialog
return _M end;
["取消"]=function(...) dialog.cancel(...) return _M end;
["關閉"]=function(...)
dialog.dismiss(...)
luajava.clear(indexBuilderPool[index])
indexBuilderPool[index]=true
return _M end;
["dismiss"]=function(...)
dialog.dismiss(...)
luajava.clear(indexBuilderPool[index])
indexBuilderPool[index]=true
return _M end;
["隱藏"]=function(...) dialog.hide(...) return _M end;
["設定按鈕"]=function(...) dialog.setButton(...) return _M end;
["設定按鈕1"]=function(...) dialog.setButton(...) return _M end;
["設定按鈕2"]=function(...) dialog.setButton(...) return _M end;
["設定按鈕3"]=function(...) dialog.setButton(...) return _M end;
["設定視圖"]=function(...) dialog.setView(...) return _M end;
["設定圖示"]=function(...) dialog.setIcon(...) return _M end;
["設定是否可以取消"]=function(...) dialog.setCancelable(...) return _M end;
["設定專案"]=function(...) dialog.setItems(...) return _M end;
["設定多選專案"]=function(...) dialog.setMultiChoiceItems(...) return _M end;
["設定取消監聽器"]=function(...) dialog.setOnCancelListener(...) return _M end;
["設定關閉監聽器"]=function(...) dialog.setOnDismissListener(...) return _M end;
["設定按鍵監聽器"]=function(...) dialog.setOnKeyListener(...) return _M end;
["設定專案選擇監聽器"]=function(...) dialog.setOnItemSelectedListener(...) return _M end;
["啟用測量時設定回收"]=function(...) dialog.setRecycleOnMeasureEnabled(...) return _M end;
["設定簡單選擇專案"]=function(...) dialog.setSingleChoiceItems(...) return _M end;
["設定自定義標題"]=function(...) dialog.setCustomTitle(...) return _M end;
["設定配接器"]=function(...) dialog.setAdapter(...) return _M end;
["設定游標"]=function(...) dialog.setCursor(...) return _M end;
["設定圖示屬性"]=function(...) dialog.setIconAttribute(...) return _M end;
["設定背景強制反向"]=function(...) dialog.setInverseBackgroundForced(...) return _M end;
["獲得按鈕"]=function(...) dialog.getButton(...) return _M end;
["獲得串列視圖"]=function(...) dialog.getListView(...) return _M end;
["當鍵按下時"]=function(...) dialog.onKeyDown(...) return _M end;
["當鍵抬起時"]=function(...) dialog.onKeyUp(...) return _M end;
["添加內容視圖"]=function(...) dialog.addContentView(...) return _M end;
["設定內容視圖"]=function(...) dialog.setContentView(...) return _M end;
["關閉選項選單"]=function(...) dialog.closeOptionsMenu(...) return _M end;
["是否正在顯示"]=function(...) dialog.isShowing(...) return _M end;
["獲得視窗"]=function(...) dialog.getWindow(...) return _M end;
["設定能否在點擊外部后取消"]=function(...) dialog.setCanceledOnTouchOutside(...) return _M end;
["設定取消訊息"]=function(...) dialog.setCancelMessage(...) return _M end;
["getThisDialogObject"]=function()return dialog end,
["獲得對話框實體"]=function()return dialog end,
}
local transC2E={
["標題"]="Title",
["訊息"]="Message",
}
setmetatable(_M,{
["__newindex"]=function(_M,k,v)
k=transC2E[k] or k
dialog[k]=v
end,
["__index"]=function(_M,method,...)
if method=="標題" or method=="Title" or method=="title" or method=="getTitle" then
return dialog.findViewById(android.R.id.icon).parent.getChildAt(1).text
end
if method=="訊息" or method=="Message" or method=="message" or method=="getMessage" then
return dialog.findViewById(android.R.id.message).text
end
_M[method]=function(...)
local a=dialog[method]
if type(a)=="function" then
a(...)
else
return a
end
return _M
end
return _M[method]
end
})
return _M
end
function 泡沫對話框(ctxOrnum,num)
if num==nil then
num=ctxOrnum
ctxOrnum=nil
end
local token="|"..tostring(tointeger(num))
local OneTimeDialogMark=activity.getSharedData("ONE-TIME-DIALOG-MARK")
if OneTimeDialogMark==nil then
OneTimeDialogMark="|"
activity.setSharedData("ONE-TIME-DIALOG-MARK",OneTimeDialogMark)
end
if OneTimeDialogMark:find(token,0,true) then
local _M={}
setmetatable(_M,{
["__index"]=function(_M,method,...)
_M[method]=function(...) return _M end
return _M[method]
end
})
return _M
end
OneTimeDialogMark=OneTimeDialogMark..token
local basedialog=對話框(ctxOrnum)
local func1=basedialog["顯示"]
local func2=basedialog["show"]
basedialog["顯示"]=function(...)
func1(...)
activity.setSharedData("ONE-TIME-DIALOG-MARK",OneTimeDialogMark)
end
basedialog["show"]=function(...)
func2(...)
activity.setSharedData("ONE-TIME-DIALOG-MARK",OneTimeDialogMark)
end
return basedialog
end
本文由【產品經理不是經理】gzh同步發布,歡迎關注
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/544712.html
標籤:其他
上一篇:【牛客】2 基礎語法
