我正在尝试实现其中一项服务,我正在使用此处的代码: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);
}
}
答案 0 :(得分:4)
我在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>
答案 1 :(得分:2)
我花了2个小时才意识到我在<accessibility-service />
文件中的.xml
标记中有错字。
我写的是<accessability-service />
而不是<accessibility-service />
。
如果您像我一样,不客气(和复制粘贴所有内容)。