示例#1
0
    @Override
    public synchronized void onResults(Bundle results) {
      ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
      Log.i(TAG, "result:");
      for (String i : matches) {
        Log.i(TAG, "onResults content: " + i);
      }
      if (MyService.this.isCalling
          && (matches.contains("no")
              || matches.contains("No")
              || matches.contains("nO")
              || matches.contains("NO"))) {
        try {
          Class clazz = Class.forName(tmgr.getClass().getName());
          Method method = clazz.getDeclaredMethod("getITelephony");
          method.setAccessible(true);
          ITelephony telephonyService = (ITelephony) method.invoke(tmgr);
          telephonyService.endCall();
          //                    MyService.this.isCalling = false;
        } catch (ClassNotFoundException e) {
          e.printStackTrace();
        } catch (NoSuchMethodException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
        }

      } else if (!MyService.this.isMakePhoneCall
          && (matches.contains("yes")
              || matches.contains("Yes")
              || matches.contains("yes")
              || matches.contains("YES"))) {
        PhoneUtil.answerRingingCall(MyService.this);
      } else {
        initComponent();
        mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
      }

      if (!MyService.this.isCalling) {
        ContentContact contentContact = MyService.this.getContactFromName(matches.get(0));
        if (contentContact != null) {
          MyService.this.makePhoneCall(contentContact.getPhoneNumber());
        }
      }
    }
示例#2
0
 private ContentContact getContactFromName(String name) {
   for (ContentContact i : contentContacts) {
     if (name.equals(i.getName())) return i;
   }
   return null;
 }