下載本文檔
版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
【移動(dòng)應(yīng)用開(kāi)發(fā)技術(shù)】Android輔助權(quán)限的示例分析
一、介紹二、配置/**
*
核心服務(wù):執(zhí)行自動(dòng)化任務(wù)
*
Created
by
czc
on
2017/6/13.
*/
public
class
TaskService_
extends
AccessibilityService{
@Override
public
void
onAccessibilityEvent(AccessibilityEvent
event)
{
//注意這個(gè)方法回調(diào),是在主線(xiàn)程,不要在這里執(zhí)行耗時(shí)操作
}
@Override
public
void
onInterrupt()
{
}
}<service
android:name=".service.TaskService"
android:enabled="true"
android:exported="true"
android:label="@string/app_name_setting"
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
<intent-filter>
<action
android:name="android.accessibilityservice.AccessibilityService"/>
</intent-filter>
<meta-data
android:name="android.accessibilityservice"
android:resource="@xml/accessibility"/>
</service><?xml
version="1.0"
encoding="utf-8"?>
<accessibility-service
xmlns:android="/apk/res/android"
<!--監(jiān)視的動(dòng)作-->
android:accessibilityEventTypes="typeAllMask"
<!--提供反饋類(lèi)型,語(yǔ)音震動(dòng)等等。-->
android:accessibilityFeedbackType="feedbackGeneric"
<!--監(jiān)視的view的狀態(tài),注意這里設(shè)置flagDefault會(huì)到時(shí)候部分界面狀態(tài)改變,不觸發(fā)onAccessibilityEvent(AccessibilityEvent
event)的回調(diào)-->
android:accessibilityFlags="flagDefault|flagRetrieveInteractiveWindows|flagIncludeNotImportantViews|flagReportViewIds|flagRequestTouchExplorationMode"
<!--是否要能夠檢索活動(dòng)窗口的內(nèi)容,此設(shè)置不能在運(yùn)行時(shí)改變-->
android:canRetrieveWindowContent="true"
<!--功能描述-->
android:description="@string/description"
<!--同一事件間隔時(shí)間名-->
android:notificationTimeout="100"
<!--監(jiān)控的軟件包名-->
android:packageNames="com.tencent.mm,com.eg.android.AlipayGphone"
/>三、核心方法accessibilityNodeInfo.findAccessibilityNodeInfosByText(text)accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id)/upload/information/20200623/125/120142.jpg四、輔助權(quán)限判斷是否開(kāi)啟public
static
boolean
hasServicePermission(Context
ct,
Class
serviceClass)
{
int
ok
=
0;
try
{
ok
=
Settings.Secure.getInt(ct.getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED);
}
catch
(Settings.SettingNotFoundException
e)
{
}
TextUtils.SimpleStringSplitter
ms
=
new
TextUtils.SimpleStringSplitter(':');
if
(ok
==
1)
{
String
settingValue
=
Settings.Secure.getString(ct.getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if
(settingValue
!=
null)
{
ms.setString(settingValue);
while
(ms.hasNext())
{
String
accessibilityService
=
ms.next();
if
(accessibilityService.contains(serviceClass.getSimpleName()))
{
return
true;
}
}
}
}
return
false;
}五、輔助的開(kāi)啟方法public
static
void
openServicePermissonRoot(Context
ct,
Class
service)
{
String
cmd1
=
"settings
put
secure
enabled_accessibility_services
"
+
ct.getPackageName()
+
"/"
+
service.getName();
String
cmd2
=
"settings
put
secure
accessibility_enabled
1";
String[]
cmds
=
new
String[]{cmd1,
cmd2};
ShellUtils.execCmd(cmds,
true);
}public
static
void
openServicePermission(Context
ct,
Class
serviceClass)
{
Set<ComponentName>
enabledServices
=
getEnabledServicesFromSettings(ct,
serviceClass);
if
(null
==
enabledServices)
{
return;
}
ComponentName
toggledService
=
ComponentName.unflattenFromString(ct.getPackageName()
+
"/"
+
serviceClass.getName());
final
boolean
accessibilityEnabled
=
true;
enabledServices.add(toggledService);
//
Update
the
enabled
services
setting.
StringBuilder
enabledServicesBuilder
=
new
StringBuilder();
for
(ComponentName
enabledService
:
enabledServices)
{
enabledServicesBuilder.append(enabledService.flattenToString());
enabledServicesBuilder.append(":");
}
final
int
enabledServicesBuilderLength
=
enabledServicesBuilder.length();
if
(enabledServicesBuilderLength
>
0)
{
enabledServicesBuilder.deleteCharAt(enabledServicesBuilderLength
-
1);
}
Settings.Secure.putString(ct.getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,
enabledServicesBuilder.toString());
//
Update
accessibility
enabled.
Settings.Secure.putInt(ct.getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED,
accessibilityEnabled
?
1
:
0);
}
public
static
Set<ComponentName>
getEnabledServicesFromSettings(Context
context,
Class
serviceClass)
{
String
enabledServicesSetting
=
Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
if
(enabledServicesSetting
==
null)
{
enabledServicesSetting
=
"";
}
Set<ComponentName>
enabledServices
=
new
HashSet<ComponentName>();
TextUtils.SimpleStringSplitter
colonSplitter
=
new
TextUtils.SimpleStringSplitter(':');
colonSplitter.setString(enabledServicesSetting);
while
(colonSplitter.hasNext())
{
String
componentNameString
=
colonSplitter.next();
ComponentName
enabledService
=
ComponentName.unflattenFromString(componentNameString);
if
(enabledService
!=
null)
{
if
(enabledService.flattenToString().contains(serviceClass.getSimpleName()))
{
return
null;
}
enabledServices.add(enabledService);
}
}
return
enabledServices;
}public
static
void
jumpSystemSetting(Context
ct)
{
//
jump
to
setting
permission
Intent
intent
=
new
Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ct.startActivity(intent);
}public
static
void
openServicePermissonCompat(final
Context
ct,
final
Class
service)
{
//輔助權(quán)限:如果root,先申請(qǐng)root權(quán)限
if
(isAppRoot())
{
if
(!hasServicePermission(ct,
service))
{
new
Thread(new
Runnable()
{
@Override
public
void
ru
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 幼兒園主題教案《冬天的小路》
- 2025屆林芝縣三年級(jí)數(shù)學(xué)第一學(xué)期期末學(xué)業(yè)質(zhì)量監(jiān)測(cè)試題含解析
- 遼寧省阜新市阜新蒙古族自治縣2024-2025學(xué)年數(shù)學(xué)三上期末復(fù)習(xí)檢測(cè)試題含解析
- 安全生產(chǎn)管理責(zé)任書(shū)(合集七篇)
- 2024年鈾及其轉(zhuǎn)化物合作協(xié)議書(shū)
- 堅(jiān)定信念講話(huà)稿5篇
- 2024年前處理系列設(shè)備項(xiàng)目合作計(jì)劃書(shū)
- 公司開(kāi)業(yè)主持稿模板5篇
- 2024年恩替卡韋項(xiàng)目建議書(shū)
- 大班分與合教學(xué)反思5篇
- 2024年機(jī)動(dòng)車(chē)輛保險(xiǎn)合同范文
- 2024-2025學(xué)年部編版語(yǔ)文七年級(jí)上冊(cè) 第一次月考試卷
- 二十屆三中全知識(shí)點(diǎn)
- 2024兒童青少年抑郁治療與康復(fù)痛點(diǎn)調(diào)研報(bào)告 -基于患者家長(zhǎng)群體的調(diào)研
- 2024廣西專(zhuān)業(yè)技術(shù)人員繼續(xù)教育公需科目參考答案(97分)
- 江蘇省建筑與裝飾工程計(jì)價(jià)定額(2014)電子表格版
- 田徑大單元教學(xué)計(jì)劃
- 中小學(xué)教師評(píng)課評(píng)價(jià)量表
- RF-CB-ZY-04-F02 工程結(jié)算書(shū)封面
- 辦公室裝修拆除施工設(shè)計(jì)方案(完整版)
- 醫(yī)院感染管理科十四五發(fā)展規(guī)劃
評(píng)論
0/150
提交評(píng)論