java - onServiceConnected not called after enable my AccessibilityService -
after open app, jumps accessibility settings. onserviceconnected
not called after have turned on accessibilityservice
(which called voiceservice
).
could please tell me should do? seems voiceservice
fails start although enable in xml. or need bind mainactivity
voiceservice
in different way?
androidmanifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.wang.hearexpr"> <uses-permission android:enabled="true" android:name="android.permission.bind_accessibility_service"/> <application android:allowbackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <service android:name=".voiceservice" android:enabled="true" android:permission="android.permission.bind_accessibility_service" android:label="@string/service_name"> <meta-data android:name="android.accessibilityservice" android:resource="@xml/voice_config"/> <intent-filter> <action android:name="android.accessibilityservice.accessibilityservice"/> </intent-filter> </service> </application> </manifest>
voice_config.xml
<?xml version="1.0" encoding="utf-8"?> <accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" android:description="@string/service_description" android:packagenames="com.example.wang.hearexpr" android:accessibilityeventtypes="typeallmask" android:accessibilityflags="flagdefault" android:accessibilityfeedbacktype="feedbackspoken" android:notificationtimeout="100" android:canretrievewindowcontent="true" android:canrequesttouchexplorationmode="true" android:settingsactivity="com.example.android.accessibility.servicesettingsactivity"/>
voiceservice.java
package com.example.wang.hearexpr; import android.accessibilityservice.accessibilityservice; import android.accessibilityservice.accessibilityserviceinfo; import android.content.intent; import android.os.handler; import android.util.log; import android.view.accessibility.accessibilityevent; public class voiceservice extends accessibilityservice { private static final string tag = "hear voice"; @override public void onserviceconnected(){ super.onserviceconnected(); log.d(tag, "service connected"); } @override public void onaccessibilityevent(accessibilityevent event) { log.d(tag,"onaccessibilityevent: "+ event.tostring()); } @override public void oninterrupt() { log.d(tag, "interrupted"); } @override public void ondestroy(){ log.d(tag, "destroyed"); } }
mainactivity.java
package com.example.wang.hearexpr; import android.content.intent; import android.provider.settings; import android.support.v7.app.appcompatactivity; import android.os.bundle; public class mainactivity extends appcompatactivity { private static final intent ssettingsintent = new intent(settings.action_accessibility_settings); @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); startactivityforresult(ssettingsintent,0); } }
this answer: in voice_config.xml
android:settingsactivity="com.example.android.accessibility.servicesettingsactivity"
should modified own activity name.
Comments
Post a Comment