FAQ FM
Разное

:: Меню ::
:: На главную ::
:: FAQ ::
:: Заметки ::
:: Практика ::
:: Win API ::
:: Проекты ::
:: Скачать ::
:: Секреты ::
:: Ссылки ::

:: Сервис ::
:: Написать ::

:: MVP ::

:: RSS ::

Яндекс.Метрика

[Android] Как вызвать диалог распознания речи?

uses
  Androidapi.JNI.GraphicsContentViewText, Androidapi.Helpers, FMX.Helpers.Android,
  Androidapi.JNIBridge, Androidapi.JNI.JavaTypes;

type
  JRecognizerIntentClass = interface(JObjectClass)
  ['{8AB8D43F-178D-4C79-9FC9-6DDA3D52CEBF}']
    {Property Methods}
    function _GetACTION_RECOGNIZE_SPEECH: JString;
    function _GetEXTRA_PROMPT: JString;
    function _GetEXTRA_LANGUAGE_MODEL: JString;
    function _GetEXTRA_MAX_RESULTS: JString;
    function _GetEXTRA_LANGUAGE: JString;
    function _GetLANGUAGE_MODEL_WEB_SEARCH: JString;
    {Properties}
    property ACTION_RECOGNIZE_SPEECH: JString read _GetACTION_RECOGNIZE_SPEECH;
    property EXTRA_PROMPT: JString read _GetEXTRA_PROMPT;
    property EXTRA_LANGUAGE_MODEL: JString read _GetEXTRA_LANGUAGE_MODEL;
    property EXTRA_MAX_RESULTS: JString read _GetEXTRA_MAX_RESULTS;
    property EXTRA_LANGUAGE: JString read _GetEXTRA_LANGUAGE;
    property LANGUAGE_MODEL_WEB_SEARCH: JString read _GetLANGUAGE_MODEL_WEB_SEARCH;
  end;

  [JavaSignature('android/speech/RecognizerIntent')]
  JRecognizerIntent = interface(JObject)
  ['{5AE872F8-D057-4966-97B9-F8DD239C3656}']
  end;

  TJRecognizerIntent = class(TJavaGenericImport<JRecognizerIntentClass, JRecognizerIntent>)
  end;

procedure OpenSpeechRecognizer;
var
  Intent: JIntent;
begin
  Intent := TJIntent.JavaClass.init(TJRecognizerIntent.JavaClass.ACTION_RECOGNIZE_SPEECH);
  Intent.putExtra(TJRecognizerIntent.JavaClass.EXTRA_PROMPT,
                  StringToJString('Голосовой поиск Inforino'));
  Intent.putExtra(TJRecognizerIntent.JavaClass.EXTRA_LANGUAGE_MODEL,
                  TJRecognizerIntent.JavaClass.LANGUAGE_MODEL_WEB_SEARCH);
  Intent.putExtra(TJRecognizerIntent.JavaClass.EXTRA_MAX_RESULTS, 1);
  Intent.putExtra(TJRecognizerIntent.JavaClass.EXTRA_LANGUAGE, StringToJString('ru-RU'));
  SharedActivity.startActivityForResult(Intent, 1);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  OpenSpeechRecognizer;
end;

initialization
  TRegTypes.RegisterType('Androidapi.JNI.GraphicsContentViewText.JDataSetObserver',
                         TypeInfo(JRecognizerIntent));


Как показать MessageBox?

uses
  {...,} FMX.DialogService;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TDialogService.MessageDialog(
    'Are you sure?',
    System.UITypes.TMsgDlgType.mtConfirmation,
    [System.UITypes.TMsgDlgBtn.mbYes, System.UITypes.TMsgDlgBtn.mbNo],
    System.UITypes.TMsgDlgBtn.mbYes,
    0,
    procedure (const AResult: System.UITypes.TModalResult)
    begin
      case AResult of
        mrYES: begin

        end;
      end;
    end
  );
end;

При использовании материала - ссылка на сайт обязательна