Esempio n. 1
0
  @Override
  public void onCreate() {
    super.onCreate();
    Log.i(TAG, "onCreate...");
    mamanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    //        amanager.setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
    //        amanager.setStreamMute(AudioManager.STREAM_ALARM, true);
    //        mamanager.setStreamMute(AudioManager.STREAM_MUSIC, true);
    //        amanager.setStreamMute(AudioManager.STREAM_RING, true);
    //        amanager.setStreamMute(AudioManager.STREAM_SYSTEM, true);
    //        mStreamVolume = mamanager.getStreamVolume(AudioManager.STREAM_MUSIC); // getting
    // system volume into var for later un-muting
    //        mamanager.setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // setting system volume
    // to zero, muting
    //        mamanager.setStreamVolume(AudioManager.STREAM_MUSIC,
    //                AudioManager.FLAG_SHOW_UI, AudioManager.FLAG_PLAY_SOUND);

    mySharedPreferences = new MySharedPreferences(this);

    mamanager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mamanager.setStreamVolume(
        AudioManager.STREAM_MUSIC, mamanager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0);
    contentContacts = CommonMethod.instance().getContentContact(this);
    //        intitTextToSpeech();
    tmgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    phoneListener = new MyPhoneStateListener();
    tmgr.listen(phoneListener, PhoneStateListener.LISTEN_CALL_STATE);

    registerBroadcastMyService();
  }
Esempio n. 2
0
    @Override
    public synchronized void onCallStateChanged(int state, String incomingNumber) {
      Log.i(TAG, "state: " + state);
      switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
          MyService.this.isCalling = true;
          String content;
          if (incomingNumber.charAt(0) == '+') {
            incomingNumber = "0" + incomingNumber.substring(2);
          }
          incomingNumber = CommonMethod.instance().convertToNumberPhone(incomingNumber);
          if (contentContacts.contains(new ContentContact(null, incomingNumber))) {
            String name =
                contentContacts
                    .get((contentContacts.indexOf(new ContentContact(null, incomingNumber))))
                    .getName();
            content = name + " calling";
          } else {
            content = incomingNumber + " calling";
          }
          Log.i(TAG, "content: " + content);
          MyService.this.startTalking(content);
          break;
          // endcall
        case TelephonyManager.CALL_STATE_IDLE:
          MyService.this.isCalling = false;
          MyService.this.isMakePhoneCall = false;
          //                    if ( MyService.this.checkRegisterBroadcastCall ) {
          //                        Log.i(TAG, "treeeeeeeeeeee");
          //                        initComponent();
          //
          // MyService.this.mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
          //                    }

          checkLoopTextToSpeechCall = false;
          if (textToSpeech != null) textToSpeech.stop();
          break;
          // answer
        case TelephonyManager.CALL_STATE_OFFHOOK:
          checkLoopTextToSpeechCall = false;
          if (textToSpeech != null) textToSpeech.stop();
          if (MyService.this.checkRegisterBroadcastCall) {
            Log.i(TAG, "treeeeeeeeeeee");
            initComponent();
            MyService.this.mSpeechRecognizer.startListening(mSpeechRecognizerIntent);
          }
          break;
      }
      super.onCallStateChanged(state, incomingNumber);
    }