自动化篇 | 再也不用担心老人们用智能机了
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
android:accessibilityEventTypes="typeWindowStateChanged"
android:accessibilityFeedbackType="feedbackGeneric"
android:accessibilityFlags="flagDefault"
android:canRetrieveWindowContent="true"
android:description="@string/desc"
android:notificationTimeout="100"
android:packageNames="com.android.packageinstaller,com.miui.packageinstaller,com.android.packageinstaller/.FlymePackageInstallerActivity" />
performGlobalAction(GLOBAL_ACTION_BACK);
private void processAccessibilityEnvent(AccessibilityEvent event)
{
String[] phoneAttrs = AppUtil.getPhoneAttrs();
if (event.getSource() != null && TextUtils.equals(event.getClassName(), phoneAttrs[0]))
{
try
{
Thread.sleep(3000);
} catch (InterruptedException e)
{
e.printStackTrace();
}
//获取应用名称
String app_name = findViewContentByID(phoneAttrs[1]);
Log.d("xag", "app_name:" + app_name);
//是否存在保留应用中
boolean isExist = false;
if (selectedApps != null && 0 < selectedApps.size())
{
for (AppBean appBean : selectedApps)
{
if (TextUtils.equals(appBean.getApp_name(), app_name))
{
isExist = true;
}
}
}
//如果不在保留应用列表,就不容许安装
if (!isExist)
{
Log.d("xag", "不在保留应用列表,不容许安装!");
performBackClick();
} else
{
Log.d("xag", "在保留应用列表,容许安装!");
}
}
}