I am facing a strange issue when I uses adMob ads with accessibility service enabled.
Once ads where received TTS engine is automatically attached to my app and showing the TTS process as in use under Settings -> Apps -> running process. There is no logic related to TTS in my app but still TTS is being attached to my app process and not releasing it.
** Note: I have tried creating a very simple app which uses only accessibility service and admob ads which confirmed this issue.
Below is the code for accessibility service:
AndroidManifest.xml
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<activity
android:name="com.example.accessibilitytestxml.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service
android:name="com.example.accessibilitytestxml.TestAccessibilityService"
android:label="Test Accessibility XML App"
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>
<!-- AdMob Code Start -->
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
<!-- AdMob Code End -->
</application>
MyAccessibilityService.java
public class TestAccessibilityService extends AccessibilityService {
...
@Override
public void onAccessibilityEvent(AccessibilityEvent event) {
System.out.println("My event: "+event.getText().toString());
}
@Override
public void onInterrupt() {
}
@Override
public void onServiceConnected() {
AccessibilityServiceInfo info = new AccessibilityServiceInfo();
info.flags = AccessibilityServiceInfo.DEFAULT;
info.eventTypes = AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED;
info.feedbackType = AccessibilityServiceInfo.FEEDBACK_GENERIC;
info.notificationTimeout = 100;
info.packageNames = null;
setServiceInfo(info);
}
...
}
Below is the simple code for Showing Ads:
MainActivity.java
final AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxx");
LinearLayout layout = (LinearLayout) findViewById(R.id.AdLinearLayout);
layout.addView(adView);
adView.loadAd(new AdRequest());
Please find the console log:
09-19 22:00:46.763: I/Ads(26011): Received ad url: <url: "http://googleads.g.doubleclick.net:80/......... type: "admob" afmaNotifyDt: "null" activationOverlayUrl: "null" useWebViewLoadUrl: "false">
09-19 22:00:46.763: I/Ads(26011): Request scenario: Online server request.
09-19 22:00:47.413: D/dalvikvm(26011): GC_CONCURRENT freed 233K, 5% free 9392K/9863K, paused 1ms+7ms
09-19 22:00:47.873: D/webviewglue(26011): nativeDestroy view: 0x1b5e98
09-19 22:00:47.903: I/TextToSpeech(26011): Sucessfully bound to com.svox.classic
09-19 22:00:47.903: I/Ads(26011): onReceiveAd()
09-19 22:00:47.943: D/dalvikvm(26011): GC_FOR_ALLOC freed 206K, 7% free 9205K/9863K, paused 34ms
09-19 22:00:48.123: I/TextToSpeech(26011): Connected to ComponentInfo{com.svox.classic/com.svox.classic.SvoxTtsService}
Your suggestions are highly appreciated.
WebView has its own JavaScript-based screen reader and connects to TTS directly when an accessibility service is enabled.