Dialogflow Google Assistant崩溃

时间:2018-12-07 16:20:03

标签: android google-assistant-sdk

我用dialogflow制作了一个聊天机器人,这正常工作。然后,我在响应中添加Google Assistant,例如:-嘿,Google Assistant的答案是“建议筹码”:-嘿。当我在Android手机上打开此应用程序时,我可以正常书写,也可以看到正常答案。但是,当我为Google Assistant保存时尝试写“ Hey”之类的东西时,应用程序崩溃。可能是由API版本引起的吗?为什么会这样呢? 代码:

public class clsPrincipal extends AppCompatActivity implements AIListener, View.OnClickListener {
private ImageButton btnVoice;
private ImageButton sendmessage;
private AIService aiService;
private static final int REQUEST_INTERNET = 200;


TextToSpeech t1;

public static String TAG = "AndroidDialogflow";

List<Message> lista;
ListView milista;
EditText message;
AIConfiguration config;


public static String API_KEY="032d9af645ac46739a1b2d576d5ff224";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.fprincipal);
    btnVoice = (ImageButton) findViewById(R.id.sendspeacker);
    lista = new ArrayList<>();

    validateOS();

    config = new AIConfiguration(API_KEY,
            AIConfiguration.SupportedLanguages.English,
            AIConfiguration.RecognitionEngine.System);

    aiService = AIService.getService(this, config);
    aiService.setListener(this);
    milista = (ListView) findViewById(R.id.chat);
    sendmessage = (ImageButton) findViewById(R.id.sendmessage);
    sendmessage.setOnClickListener(this);

    btnVoice.setOnClickListener(this);
    t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            if (status != TextToSpeech.ERROR) {
                Locale locSpanish = new Locale("spa", "MEX");
                t1.setLanguage(locSpanish);
            }
        }
    });

    message = (EditText) findViewById(R.id.textmessage);


}

private void validateOS() {
    if (ContextCompat.checkSelfPermission(clsPrincipal.this, Manifest.permission.RECORD_AUDIO) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(clsPrincipal.this, new String[]{Manifest.permission.RECORD_AUDIO}, REQUEST_INTERNET);
        ActivityCompat.requestPermissions(clsPrincipal.this, new String[]{Manifest.permission.RECORD_AUDIO}, REQUEST_INTERNET);
    }
}

@Override
public void onResult(AIResponse response) {
    Result result = response.getResult();
    final Status status = response.getStatus();
    Log.i(TAG, "Status code: " + status.getCode());
    Log.i(TAG, "Status type: " + status.getErrorType());
    final Metadata metadata = result.getMetadata();
    if (metadata != null) {
        Log.i(TAG, "Intent id: " + metadata.getIntentId());
        Log.i(TAG, "Intent name: " + metadata.getIntentName());
    }
    String parameterString = "";
    if (result.getParameters() != null && !result.getParameters().isEmpty()) {
        for (final Map.Entry<String, JsonElement> entry : result.getParameters().entrySet()) {
            parameterString += "(" + entry.getKey() + ", " + entry.getValue();
        }
    }
    String cad = response.getResult().getFulfillment().getSpeech().toString();
    if (cad.compareTo("") == 0) {
        cad = "Hata meydana geldi";
    }
    // text to speech get text response
    t1.speak(cad, TextToSpeech.QUEUE_FLUSH, null);
    lista.add(new Message(result.getResolvedQuery(), 1));
    lista.add(new Message(cad, 0));
    AdapMessage adap = new AdapMessage(lista, this);
    milista.setAdapter(adap);
}

@Override
public void onError(AIError error) {
    Log.e(TAG,error.toString());
}

@Override
public void onAudioLevel(float level) {

}

@Override
public void onListeningStarted() {

}

@Override
public void onListeningCanceled() {

}

@Override
public void onListeningFinished() {

}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.sendspeacker:
            aiService.startListening();
            break;
        case R.id.sendmessage:
            SendText(message.getText().toString());
            break;
    }
}

void SendText(String query) {
    final AIConfiguration config = new AIConfiguration(API_KEY,
            AIConfiguration.SupportedLanguages.English,
            AIConfiguration.RecognitionEngine.System);
    final AIDataService aiDataService = new AIDataService(this,config);
    final AIRequest aiRequest = new AIRequest();
    aiRequest.setQuery(query);

    new AsyncTask<AIRequest, Void, AIResponse>() {
        private final ProgressDialog dialog = new ProgressDialog(clsPrincipal.this);
        protected void onPreExecute() {
            this.dialog.setMessage("Mesaj gönderiliyor...");
            this.dialog.show();
            super.onPreExecute();
        }

        @Override
        protected AIResponse doInBackground(AIRequest... requests) {
            final AIRequest request = requests[0];
            try {
                final AIResponse response = aiDataService.request(aiRequest);
                return response;
            } catch (AIServiceException e) {
            }
            return null;
        }
        @Override
        protected void onPostExecute(AIResponse aiResponse) {
            if (aiResponse != null) {
                // process aiResponse here
                Result result = aiResponse.getResult();
                String cad = aiResponse.getResult().getFulfillment().getSpeech().toString();
                if (cad.compareTo("") == 0) {
                    cad = "Hata oluştu";
                }
                t1.speak(cad, TextToSpeech.QUEUE_FLUSH, null);
                lista.add(new Message(result.getResolvedQuery(), 1));
                lista.add(new Message(cad, 0));
                AdapMessage adap = new AdapMessage(lista, clsPrincipal.this);
                milista.setAdapter(adap);
                if (dialog.isShowing()) {
                    dialog.dismiss();
                }
                message.setText("");

            }
        }
    }.execute(aiRequest);
}
}

Logcat:

12-08 10:13:04.965 8476-8533/com.codigopanda.androiddialogflow E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: com.codigopanda.androiddialogflow, PID: 8476
java.lang.RuntimeException: An error occurred while executing doInBackground()
    at android.os.AsyncTask$3.done(AsyncTask.java:309)
    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
    at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)
 Caused by: java.lang.NumberFormatException: Invalid int: "suggestion_chips"
    at java.lang.Integer.invalidInt(Integer.java:138)
    at java.lang.Integer.parse(Integer.java:410)
    at java.lang.Integer.parseInt(Integer.java:367)
    at java.lang.Integer.parseInt(Integer.java:334)
    at com.google.gson.JsonPrimitive.getAsInt(JsonPrimitive.java:260)
    at ai.api.GsonFactory$ResponseItemAdapter.deserialize(GsonFactory.java:78)
    at ai.api.GsonFactory$ResponseItemAdapter.deserialize(GsonFactory.java:71)
    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69)
    at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:41)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:82)
    at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:61)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
    at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
    at com.google.gson.Gson.fromJson(Gson.java:887)
    at com.google.gson.Gson.fromJson(Gson.java:852)
    at com.google.gson.Gson.fromJson(Gson.java:801)
    at com.google.gson.Gson.fromJson(Gson.java:773)
    at ai.api.AIDataService.request(AIDataService.java:193)
    at ai.api.AIDataService.request(AIDataService.java:148)
    at ai.api.AIDataService.request(AIDataService.java:124)
    at com.berkancalikoglu.mesajlas.clsPrincipal$2.doInBackground(clsPrincipal.java:175)
    at com.berkancalikoglu.mesajlas.clsPrincipal$2.doInBackground(clsPrincipal.java:167)
    at android.os.AsyncTask$2.call(AsyncTask.java:295)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
    at java.lang.Thread.run(Thread.java:818) 
12-08 10:13:04.967 2002-3970/system_process W/ActivityManager:   Force finishing activity com.codigopanda.androiddialogflow/com.berkancalikoglu.mesajlas.clsPrincipal
12-08 10:13:04.974 1269-1425/? D/gralloc_ranchu: gralloc_alloc: Creating ashmem region of size 331776
12-08 10:13:04.986 1269-1269/? E/EGL_emulation: tid 1269: eglCreateSyncKHR(1881): error 0x3004 (EGL_BAD_ATTRIBUTE)
12-08 10:13:05.123 8476-8520/com.codigopanda.androiddialogflow D/EGL_emulation: eglMakeCurrent: 0x7f864d962fa0: ver 2 0 (tinfo 0x7f864d943900)
12-08 10:13:05.131 8476-8520/com.codigopanda.androiddialogflow E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f864d963720
12-08 10:13:05.137 2002-6238/system_process I/OpenGLRenderer: Initialized EGL, version 1.4
12-08 10:13:05.139 2002-6238/system_process D/EGL_emulation: eglCreateContext: 0x7f863907b400: maj 2 min 0 rcv 2
12-08 10:13:05.142 8476-8520/com.codigopanda.androiddialogflow D/OpenGLRenderer: endAllStagingAnimators on 0x7f8641336000 (RippleDrawable) with handle 0x7f8640f3e8c0
12-08 10:13:05.145 2002-6238/system_process D/EGL_emulation: eglMakeCurrent: 0x7f863907b400: ver 2 0 (tinfo 0x7f863ba2bb60)
12-08 10:13:05.159 2002-6238/system_process D/EGL_emulation: eglMakeCurrent: 0x7f863907b400: ver 2 0 (tinfo 0x7f863ba2bb60)
12-08 10:13:05.188 3194-3283/com.android.launcher3 D/EGL_emulation: eglMakeCurrent: 0x7f864a0dc060: ver 2 0 (tinfo 0x7f864271e960)
12-08 10:13:05.266 2002-2014/system_process I/AccountManagerService: getTypesVisibleToCaller: isPermitted? true
12-08 10:13:07.880 1693-1992/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 20467322 , only wrote 20330377
12-08 10:13:07.891 8476-8533/? I/Process: Sending signal. PID: 8476 SIG: 9
12-08 10:13:07.894 2002-6238/system_process D/EGL_emulation: eglMakeCurrent: 0x7f863907b400: ver 2 0 (tinfo 0x7f863ba2bb60)
12-08 10:13:07.896 2002-6238/system_process E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f863ba05200
12-08 10:13:07.916 2002-2340/system_process D/GraphicsStats: Buffer count: 4
12-08 10:13:07.919 2002-2231/system_process W/InputMethodManagerService: Got RemoteException sending setActive(false) notification to pid 8476 uid 10064
12-08 10:13:07.934 1693-1992/? D/AudioFlinger: mixer(0xf4300000) throttle end: throttle time(11)
12-08 10:13:07.946 2002-2338/system_process I/ActivityManager: Process com.codigopanda.androiddialogflow (pid 8476) has died
12-08 10:13:07.954 2570-5483/com.android.inputmethod.latin D/EGL_emulation: eglMakeCurrent: 0x7f864a0dc420: ver 2 0 (tinfo 0x7f86519bfca0)
12-08 10:13:07.955 2378-2883/com.android.systemui D/EGL_emulation: eglMakeCurrent: 0x7f86414dcaa0: ver 2 0 (tinfo 0x7f8641a963e0)
12-08 10:13:07.958 2570-5483/com.android.inputmethod.latin E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7f86409a32c0
12-08 10:13:08.091 2002-2023/system_process W/AppOps: Finishing op nesting under-run: uid 1000 pkg android code 24 time=0 duration=0 nesting=0
12-08 10:13:08.357 2378-2883/com.android.systemui D/EGL_emulation: eglMakeCurrent: 0x7f86414dcaa0: ver 2 0 (tinfo 0x7f8641a963e0)
12-08 10:13:11.040 1693-1992/? W/audio_hw_generic: Not supplying enough data to HAL, expected position 20604829 , only wrote 20468526

0 个答案:

没有答案