zoukankan      html  css  js  c++  java
  • 使用AccessibilityService执行开机自启动

    res/xml/accessibility_service_config.xml

    <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android"
    android:canRetrieveWindowContent="false"
    android:description="@string/xxxxxxx"
    android:notificationTimeout="100"
    android:packageNames="com.android.launcher" />

    <uses-permission android:name="android.permission.BIND_ACCESSIBILITY_SERVICE" />

    <service
    android:name=".BService"
    android:label="开机辅助"
    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_config" />
    </service>

    <string name="xxxxxxx">开机辅助</string>

    //判断服务是否打开
    private boolean isAccessibilitySettingsOn(Context mContext) {
    int accessibilityEnabled = 0;
    final String service = getPackageName() + "/" + BService.class.getCanonicalName();
    try {
    accessibilityEnabled = Settings.Secure.getInt(mContext.getApplicationContext().getContentResolver(),
    android.provider.Settings.Secure.ACCESSIBILITY_ENABLED);
    Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled);
    } catch (Settings.SettingNotFoundException e) {
    Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage());
    }
    TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

    if (accessibilityEnabled == 1) {
    Log.v(TAG, "***ACCESSIBILITY IS ENABLED*** -----------------");
    String settingValue = Settings.Secure.getString(mContext.getApplicationContext().getContentResolver(),
    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
    if (settingValue != null) {
    mStringColonSplitter.setString(settingValue);
    while (mStringColonSplitter.hasNext()) {
    String accessibilityService = mStringColonSplitter.next();

    Log.v(TAG, "-------------- > accessibilityService :: " + accessibilityService + " " + service);
    if (accessibilityService.equalsIgnoreCase(service)) {
    Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
    return true;
    }
    }
    }
    } else {
    Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
    }

    return false;
    }

    if (!isAccessibilitySettingsOn(this)) {
    Toast.makeText(this, "请打开开机辅助!", Toast.LENGTH_LONG).show();
    Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    }

  • 相关阅读:
    NTP on FreeBSD 12.1
    Set proxy server on FreeBSD 12.1
    win32 disk imager使用后u盘容量恢复
    How to install Google Chrome Browser on Kali Linux
    Set NTP Service and timezone on Kali Linux
    Set static IP address and DNS on FreeBSD
    github博客标题显示不了可能是标题包含 特殊符号比如 : (冒号)
    server certificate verification failed. CAfile: none CRLfile: none
    删除文件和目录(彻底的)
    如何在Curl中使用Socks5代理
  • 原文地址:https://www.cnblogs.com/lzh-Linux/p/6001628.html
Copyright © 2011-2022 走看看