当我使用启用了无障碍服务的 adMob 广告时,我遇到了一个奇怪的问题。
一旦收到 TTS 引擎的广告会自动附加到我的应用程序,并在设置 -> 应用程序 -> 运行进程下显示 TTS 进程正在使用中。我的应用程序中没有与 TTS 相关的逻辑,但 TTS 仍然附加到我的应用程序进程并且没有释放它。
** 注意:我尝试创建一个非常简单的应用程序,该应用程序仅使用可确认此问题的无障碍服务和 admob 广告。
以下是无障碍服务的代码:
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);
}
...
}
以下是展示广告的简单代码:
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());
请找到控制台日志:
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}
非常感谢您的建议。