0

我需要在应用程序覆盖上方打开 Google Speech RecognizerIntent。我在 Overy 源代码和 RecognizerIntent 下面添加了。请指导。

private void overLay(){
    WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    View testView = LayoutInflater.from(getApplicationContext()).inflate(R.layout.overlay, null);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
            PixelFormat.TRANSLUCENT);

    LinearLayoutCompat linearLayoutOverLay = (LinearLayoutCompat) testView.findViewById(R.id.linearLayoutOverLay);
    AppCompatImageView imageViewStopOL =  (AppCompatImageView)testView.findViewById(R.id.imageViewStopOL);
   AppCompatImageView imageViewGoogle = (AppCompatImageView)testView.findViewById(R.id.imageViewGoogle);


    imageViewStopOL.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            windowManager.removeViewImmediate(testView);

        }
    });
    
    windowManager.addView(testView , params);
}

public void askSpeechInput() { if(!SpeechRecognizer.isRecognitionAvailable(this)) { Toast.makeText(this, "语音识别不可用", Toast.LENGTH_SHORT).show(); }别的 {

        Intent i =new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
        i.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
        i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say Something!");
        startActivityForResult(i, 200);

    } 

}

4

0 回答 0