0

Android 4.0以上のバージョンで自動着信できる機能を設定したいです。このようなコード:</p>

synchronized void autoAnswerCall(){

  Context context = TApplication.nowApplication;

   try

         {

          //insert earphones

             Intent localIntent1 = new Intent(Intent.ACTION_HEADSET_PLUG);

             localIntent1.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

             localIntent1.putExtra("state", 1);

             localIntent1.putExtra("microphone", 1);

             localIntent1.putExtra("name", "Headset");

             context.sendOrderedBroadcast(localIntent1, "android.permission.CALL_PRIVILEGED");


             //Press the headset button

             Intent localIntent2 = new Intent(Intent.ACTION_MEDIA_BUTTON);

             KeyEvent localKeyEvent1 = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_HEADSETHOOK);

             localIntent2.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent1);

             context.sendOrderedBroadcast(localIntent2, "android.permission.CALL_PRIVILEGED");


             //Open the headset button

             Intent localIntent3 = new Intent(Intent.ACTION_MEDIA_BUTTON);

             KeyEvent localKeyEvent2 = new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_HEADSETHOOK);

             localIntent3.putExtra("android.intent.extra.KEY_EVENT", localKeyEvent2);

             context.sendOrderedBroadcast(localIntent3, "android.permission.CALL_PRIVILEGED");


             //Pull out earphones

             Intent localIntent4 = new Intent(Intent.ACTION_HEADSET_PLUG);

             localIntent4.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

             localIntent4.putExtra("state", 0);

             localIntent4.putExtra("microphone", 1);

             localIntent4.putExtra("name", "Headset");

             context.sendOrderedBroadcast(localIntent4, "android.permission.CALL_PRIVILEGED");

         }catch (Exception e){

             e.printStackTrace();

         }

}

シミュレーターと携帯電話のandroid2.3で自動応答機能を実現しました。android4.0シミュレーターでも可能です。しかし、android4.0 携帯電話ではできません。

私は補助反射を使用していますが、できません。携帯電話のandroid4.0で自動応答機能を実現するには?</p>

4

1 に答える 1

0

テレフォニーマネージャーを使用して呼び出し中の通話を受信できます。このためには、このコードをブロードキャストレシーバーに配置する必要があります。

 if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
        {          
            TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);  
            Class c = null;
                 c = Class.forName(telephony.getClass().getName());
                 Method m = null;
                 m = c.getDeclaredMethod("getITelephony");
                 m.setAccessible(true);              
                telephonyService = (ITelephony) m.invoke(telephony);
                telephonyService.answerRingingCall();

       }
于 2013-01-05T09:31:53.290 に答える