android - 如何检查 TtsService(或 Android 服务)是否停止?

标签 android android-service text-to-speech

原因beyond我的应用程序的控件 TtsService 被系统停止,在 LogCat 中仅提供 Log.i() 提示:

05-01 12:01:55.662: INFO/TtsService(1791): Stopping
05-01 12:01:55.662: INFO/TtsService(1791): Stopped

我希望能够在我的应用中处理这种情况。

有没有办法(回调或系统调用)检测何时发生这种情况?

如果没有,有没有办法检查TTS服务是否正在运行?

最佳答案

您可以使用以下方法检查服务是否正在运行。

ServiceName = "package.service".\\service name
public static boolean isServiceRunning(Context ctx, String serviceName) 
    {
        ActivityManager manager = (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE);
        for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
            if (serviceName.equalsIgnoreCase(service.service.getClassName())) {
                Log.v(TAG,serviceName+": Service running");
                return true;
            }
        }
        return false;
    }

关于android - 如何检查 TtsService(或 Android 服务)是否停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5857640/

相关文章:

android - 服务中的 SurfaceView

android - 在后台服务中使用 Google Play Services LocationClient

android - 应用程序在 android 中被杀死后后台服务不工作

android - 为什么文本转语音 (TTS) 不能一直工作?

Android保存图像(经过一些处理)最佳方法

android - 在android上绘制凸包

java - 当安卓手机处于深度 sleep 模式时捕捉按键

java - 我如何应用alertDialog作为AsyncTask中的服务器响应

cocoa - Cocoa 语音问题简介

python - pyttsx 引擎 runAndWait 在 Yosemite 上不返回的解决方法