對于一個依賴無障礙服務(wù)的應(yīng)用來說,App關(guān)閉的時候就會關(guān)閉無障礙服務(wù)權(quán)限,以至于每次啟動都需要去手動打開一次無障礙服務(wù),這無疑會讓人很抓狂.但是這對于用戶來說這又是安全的,否則各種流氓豈不是可以隨意操控你的手機了,有限制才會有安全...
今天的這篇文章呢,是利用一個系統(tǒng)的權(quán)限
android.permission.WRITE_SECURE_SETTINGS
這個權(quán)限對于開發(fā)安裝的人來說,都應(yīng)該明白,如果我們直接在AndroidMainifast.xml中聲明,會報錯,原因就是我們不是系統(tǒng)應(yīng)用,屬于第三方,所以沒有權(quán)限使用這個權(quán)限.但是如果我們使用adb調(diào)試來針對某一個app來授權(quán),那就可以拿到這個權(quán)限了,授權(quán)的命令為:
adb shell pm grant PACKAGE_NAME android.permission.WRITE_SECURE_SETTINGS
其中PACKAGE_NAME為你要授權(quán)的應(yīng)用包名.例如: org.autojs.autojspro
adb命令如何安裝到你的電腦上,如何使用我就不教了,自行百度吧.其他的廢話,我也不多說了,直接上我們今天的腳本代碼.
importClass(android.content.Context);
importClass(android.provider.Settings);
importClass(android.content.pm.PackageManager);
if (!checkSelfPermission("android.permission.WRITE_SECURE_SETTINGS")) {
toastLog("出錯了,請查看日志界面內(nèi)容");
console.error("\\n您沒有為autojs/autojsPro授予WRITE_SECURE_SETTINGS權(quán)限!\\n"+
"授權(quán)方法: 您需要打開USB調(diào)試并連接一臺電腦,使用adb命令給autojs授權(quán),命令為:\\n"+
"adb shell pm grant "+context.getPackageName()+" android.permission.WRITE_SECURE_SETTINGS");
setClip("adb shell pm grant "+context.getPackageName()+" android.permission.WRITE_SECURE_SETTINGS");
toastLog("命令已寫入到剪貼板");
exit();
}
if (auto.service == null) {
//這里沒有啟動無障礙服務(wù) 這里我啟動了autojs免費版和pro版的無障礙服務(wù)
try {
var enabledServices = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
var Services = enabledServices + ":org.autojs.autojspro/com.stardust.autojs.core.accessibility.AccessibilityService"+
":org.autojs.autojs/com.stardust.autojs.core.accessibility.AccessibilityService";
Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, Services);
Settings.Secure.putString(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, '1');
} catch (e) {
toastLog("您沒有為autojs/autojsPro授予WRITE_SECURE_SETTINGS權(quán)限");
exit();
}
}
/**
* 檢查自身是否開啟某權(quán)限
* @param {string} permission 權(quán)限名稱
*/
function checkSelfPermission(permission) {
return context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED
}
-
APP
+關(guān)注
關(guān)注
33文章
1584瀏覽量
73595 -
系統(tǒng)應(yīng)用
+關(guān)注
關(guān)注
0文章
3瀏覽量
5179 -
adb
+關(guān)注
關(guān)注
1文章
39瀏覽量
10613
發(fā)布評論請先 登錄
相關(guān)推薦
HarmonyOS NEXT應(yīng)用元服務(wù)開發(fā)Accessibility(信息無障礙)介紹
怎樣做才能讓RK3326 Android為自己的APK服務(wù)開啟無障礙默認權(quán)限呢
RK3322 Android 8.1是如何為自己的APK服務(wù)開啟無障礙權(quán)限的
MIUI發(fā)布MIUI12.5無障礙觸感功能
工信部:年底將授予首批無障礙標識
2021華為開發(fā)者大會:手語Sign pal Kit 開放服務(wù) 助力溝通無障礙

評論