Android ";“网络未连接”;在模拟器和真实设备上使用语音识别时

Android ";“网络未连接”;在模拟器和真实设备上使用语音识别时,android,android-emulator,android-manifest,voice-recognition,Android,Android Emulator,Android Manifest,Voice Recognition,我正在尝试使用Android Studio进行语音识别工作 我正在使用来自的教程 我意识到语音识别的一些典型问题,因此我再次检查: 我的清单文件包含其他权限 网络在仿真器上工作 测试语音识别器是否可用-通过 我已经在emulator(Nexus 5X API 28 x86)上测试了它 语音识别显示“网络未连接”(事实并非如此): 我的清单文件: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht

我正在尝试使用Android Studio进行语音识别工作

我正在使用来自的教程

我意识到语音识别的一些典型问题,因此我再次检查:

  • 我的清单文件包含其他权限
  • 网络在仿真器上工作
  • 测试语音识别器是否可用-通过
  • 我已经在emulator(Nexus 5X API 28 x86)上测试了它

    语音识别显示“网络未连接”(事实并非如此):

    我的清单文件:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.mei.chat">
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name="com.example.mei.chat.SimpleVoiceRecognition"
            android:label="@string/title_activity_simple_voice_recognition"
            android:theme="@style/AppTheme.NoActionBar"></activity>
        <activity android:name="com.example.mei.chat.MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    
    </manifest>
    
    为了测试emulator上的语音识别器是否可用,我使用了以下代码:

    PackageManager pm = getPackageManager();
    List activities = pm.queryIntentActivities(new Intent(
        RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0) {
        Toast.makeText(this, "Voice recognizer is not available in your device", Toast.LENGTH_SHORT).show();
    }else{
        Toast.makeText(this, "OK. Voice recognizer is available.", Toast.LENGTH_SHORT).show();
    }
    

    识别器需要一个到谷歌服务器的Intellet连接。不管出于什么原因,你都没有。识别器需要一个到谷歌服务器的Intellet连接。不管什么原因,你都没有。
    03/15 18:44:12: Launching app
    $ adb shell am start -n "com.example.sergeherkul.hellotoast/com.example.mei.chat.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
    Client not ready yet..Waiting for process to come online
    Connected to process 18254 on device Nexus_5X_API_28_x86 [emulator-5554]
    Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
    I/rkul.hellotoas: Not late-enabling -Xcheck:jni (already on)
    W/rkul.hellotoas: Unexpected CPU variant for X86 using defaults: x86
    I/rkul.hellotoas: The ClassLoaderContext is a special shared library.
    W/rkul.hellotoas: JIT profile information will not be recorded: profile file does not exits.
    I/chatty: uid=10086(com.example.sergeherkul.hellotoast) identical 10 lines
    W/rkul.hellotoas: JIT profile information will not be recorded: profile file does not exits.
    I/InstantRun: starting instant run server: is main process
    D/OpenGLRenderer: Skia GL Pipeline
    D/: HostConnection::get() New Host Connection established 0xe0894b80, tid 18280
    I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasWideColorDisplay retrieved: 0
    I/ConfigStore: android::hardware::configstore::V1_0::ISurfaceFlingerConfigs::hasHDRDisplay retrieved: 0
    I/OpenGLRenderer: Initialized EGL, version 1.4
    D/OpenGLRenderer: Swap behavior 1
    W/OpenGLRenderer: Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without...
    D/OpenGLRenderer: Swap behavior 0
    D/EGL_emulation: eglCreateContext: 0xe40de700: maj 3 min 1 rcv 4
    D/EGL_emulation: eglMakeCurrent: 0xe40de700: ver 3 1 (tinfo 0xe8047b00)
    E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
    E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
    D/EGL_emulation: eglMakeCurrent: 0xe40de700: ver 3 1 (tinfo 0xe8047b00)
    
    PackageManager pm = getPackageManager();
    List activities = pm.queryIntentActivities(new Intent(
        RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
    if (activities.size() == 0) {
        Toast.makeText(this, "Voice recognizer is not available in your device", Toast.LENGTH_SHORT).show();
    }else{
        Toast.makeText(this, "OK. Voice recognizer is available.", Toast.LENGTH_SHORT).show();
    }