如何在Android中确定/获取正确的S语音包 [英] How to determine/get correct S Voice packet in Android

查看:125
本文介绍了如何在Android中确定/获取正确的S语音包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Android打开Android中的S语音应用程序.作为以前的工作,我将使用以下代码将其打开

I am using Android to turn on my S Voice application in Android. As previous work, I will use the follows code to turn on it

String SVOICE_PACKAGE_NAME = "com.vlingo.midas";
String SVOICE_LISTEN_ACTION = "com.sec.action.SVOICE";
Intent intent = new Intent();
intent.setPackage(SVOICE_PACKAGE_NAME);
intent.setAction(SVOICE_LISTEN_ACTION);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
try {
    getApplication().startActivity(intent);
} catch (final ActivityNotFoundException e) {
    e.printStackTrace();
} catch (final Exception e) {
    e.printStackTrace();
}

以上代码在带有Android 5.0的Galaxy S4中运行良好.但是,问题来自带有Android 6.0的Galaxy S7的第一和第二行.在装有Android 6.0的Galaxy S7中,第一行和第二行必须修改为

The above code worked well in Galaxy S4 with Android 5.0. However, the issue comes from first and second lines in Galaxy S7 with Android 6.0. In Galaxy S7 with Android 6.0, the first and second lines have to modify as

SVOICE_PACKAGE_NAME = "com.samsung.voiceserviceplatform";
SVOICE_LISTEN_ACTION = "com.sec.action.SVOICE";

应用程序名称S语音(从"S语音"更改为"S语音应用").这种变化给我带来了艰巨的工作.因此,在决定调用这些功能之前,我想确定手机中的S Voice App.目前,我不知道更改是从Android版本还是从设备开始.您是否有任何想法可以在各种手机(S4和S7)中解决此问题?

And also the application name S Voice with changing from "S Voice" to "S Voice App". That changing gives me a difficult work. Hence, I want to determine the S Voice App in my phone before deciding calls these function. Currently, I do not know the changing is from Android version or the device. Could you have any idea to adapt the issue in various phones: S4 and S7?

推荐答案

每当打开应用程序时,程序包或应用程序名称可能会有所不同.这是要检查的标准实用程序方法:

Whenever opening applications, there could be package or application name differences. Here is a standard utility method to check:

/**
 * Check if the user has a package installed
 *
 * @param ctx         the application context
 * @param packageName the application package name
 * @return true if the package is installed
 */
public static boolean isPackageInstalled(@NonNull final Context ctx, @NonNull final String packageName) {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "isPackageInstalled");
    }

    try {
        ctx.getApplicationContext().getPackageManager().getApplicationInfo(packageName, 0);
        return true;
    } catch (final PackageManager.NameNotFoundException e) {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "isPackageInstalled: NameNotFoundException");
        }
    } catch (final NullPointerException e) {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "isPackageInstalled: NullPointerException");
        }
    } catch (final Exception e) {
        if (DEBUG) {
            MyLog.w(CLS_NAME, "isPackageInstalled: Exception");
        }
    }

    return false;
}

您需要删除我的自定义日志记录.

You'll need to remove my custom logging.

这篇关于如何在Android中确定/获取正确的S语音包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆