2

好吧,我正在尝试实现其中一项服务,我正在使用此处的代码:http: //developer.android.com/training/accessibility/service.html#create但我无法启用该服务,因为我在系统设置中看不到。谁能帮帮我?

显现:

<service android:name=".MyAccessibilityService" >
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>
    </service>

MyAccessibilityService.java

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.util.Log;
import android.view.accessibility.AccessibilityEvent;
import android.widget.Toast;

public class MyAccessibilityService extends AccessibilityService
{
public static final String TAG = "volumeMaster";

@Override
public void onAccessibilityEvent(AccessibilityEvent event)
{
    Log.v(TAG, "***** onAccessibilityEvent");
    Toast.makeText(getApplicationContext(), "Got event from: " + event.getPackageName(), Toast.LENGTH_LONG).show();
}

@Override
public void onInterrupt()
{
    Log.v(TAG, "***** onInterrupt");
}

@Override
public void onServiceConnected()
{
    Log.v(TAG, "***** onServiceConnected");

    AccessibilityServiceInfo info = new AccessibilityServiceInfo();
    info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
    info.notificationTimeout = 100;
    info.feedbackType = AccessibilityEvent.TYPES_ALL_MASK;
    setServiceInfo(info);

}
}
4

2 回答 2

5

好吧,我在 中留下了一些重要的东西AndroidManifest.xml,所以现在它工作得很好。这是新的清单

    <service
        android:name=".NotificationService"
        android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"
        class=".NotificationService"
        android:enabled="true"
        android:exported="false" >
        <intent-filter>
            <action
                android:name=".NotificationService"
                android:value=".NotificationService" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>

    </service>
于 2013-08-17T19:09:26.950 回答
2

我花了 2 小时才意识到我的文件中的<accessibility-service />标签有错字。.xml

我写<accessability-service />的不是<accessibility-service />.

如果您像我一样,不客气(并复制所有内容)。

于 2020-03-16T15:19:15.430 回答