【问题标题】:Error running Google Voice API code运行 Google Voice API 代码时出错
【发布时间】:2016-11-27 00:35:58
【问题描述】:

凭借我对 Android 的基本了解,我正在尝试使用 Google 语音 API,并按照示例 here 编写一个应用程序,该应用程序允许我拨打一个硬编码的号码。不幸的是,我收到一条错误消息,提示 是预期的,所以我无法检查我的应用程序是否可以正常工作。有人可以看到这里缺少什么,以及我的思维和代码是否朝着正确的方向前进。

Java 文件:

public class MyVoiceActivity extends Activity {
class Confirm extends VoiceInteractor.ConfirmationRequest {
    public Confirm(String ttsPrompt, String visualPrompt) {
        VoiceInteractor.Prompt prompt = new VoiceInteractor.Prompt(
                new String[] {ttsPrompt}, visualPrompt);
        super(prompt, null);
    }

    @Override public void onConfirmationResult(boolean confirmed, Bundle null)    {
        if (confirmed) {
            call();
        }
        finish();
    }

};

@Override public void onResume() {
    if (isVoiceInteractionRoot()) {
        call();
    }

    Intent intent = new Intent(this, MyVoiceActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
    finish();
}

private void call () {
    try {

        final Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse("tel:12345678"));
        startActivity(callIntent);
    } catch (ActivityNotFoundException activityException) {

    }
  }
}

AndroidManifest 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ccvoice.bt.examplevoice">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity
        android:name=".MyVoiceActivity" >
    <intent-filter>
        <action android:name="android.intent.action.CALL" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.VOICE" />
    </intent-filter>

    </activity>

</application>

</manifest>

我得到的 required 错误在这行代码中:

public void onConfirmationResult(boolean confirmed, Bundle null) {

提前谢谢你。

【问题讨论】:

    标签: android google-api google-voice google-voice-search google-voice-actions


    【解决方案1】:

    null 是保留字,不能用作标识符(例如参数的名称)。为您的 Bundle 参数使用与该方法不同的名称。

    public void onConfirmationResult(boolean confirmed, Bundle bundle) {
    

    【讨论】:

    • 感谢您修复了该错误,但我现在遇到了更多错误。 Error:(16, 63) error: constructor ConfirmationRequest in class ConfirmationRequest cannot be applied to given types; required: Prompt,Bundle found: no arguments reason: actual and formal argument lists differ in lengthError:(19, 18) error: call to super must be first statement in constructorError:Execution failed for task ':app:compileDebugJavaWithJavac'. &gt; Compilation failed; see the compiler error output for details.
    猜你喜欢
    • 2014-04-26
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-16
    相关资源
    最近更新 更多