--仅供娱乐
--仅供娱乐
--仅供娱乐
--自己写下载逻辑
--实现:检测手机是否安装原神,有则启动,否则锁定屏幕强制安装
--可能有一堆bug大佬自行修复😅
require "import"
import "android.content.Intent"
import "android.net.Uri"
import "android.widget.Toast"
-- 判断用户是否安装了指定应用
function isAppInstalled(packageName)
local pm = activity.getPackageManager()
local packages = pm.getInstalledPackages(0)
for i = 0, packages.size() - 1 do
local packageInfo = packages.get(i)
if packageName == packageInfo.packageName then
return true
end
end
return false
end
-- 启动应用
function startApp(packageName)
local intent = activity.getPackageManager().getLaunchIntentForPackage(packageName)
if intent then
activity.startActivity(intent)
end
end
-- 下载文件并锁定屏幕
function downloadAndLockScreen(url)
-- 下载文件逻辑
-- ...
-- 假设下载成功
local downloadSuccess = true
if downloadSuccess then
-- 解锁屏幕并打开下载的文件
unlockScreen()
openDownloadedFile()
else
-- 锁定屏幕5秒后解锁
lockScreen()
sleep(5000)
unlockScreen()
end
end
-- 解锁屏幕
function unlockScreen()
local devicePolicyManager = activity.getSystemService(Context.DEVICE_POLICY_SERVICE)
devicePolicyManager.resetPassword("", 0) -- 解锁屏幕
end
-- 锁定屏幕
function lockScreen()
local devicePolicyManager = activity.getSystemService(Context.DEVICE_POLICY_SERVICE)
devicePolicyManager.lockNow() -- 锁定屏幕
end
-- 打开下载的文件
function openDownloadedFile()
local intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(Uri.parse("file:///path/to/downloaded/file.apk"), "application/vnd.android.package-archive")
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
activity.startActivity(intent)
end
-- 主逻辑
if isAppInstalled("com.miHoYo.cloudgames.ys") or isAppInstalled("com.miHoYo.Yuanshen") then
startApp("com.miHoYo.cloudgames.ys")
startApp("com.miHoYo.Yuanshen")
Toast.makeText(activity,"原神,启动!", Toast.LENGTH_LONG).show()
else
local apkUrl = "http://xxx.com/xxx.apk"
downloadAndLockScreen(apkUrl)
end