1

안녕하세요 여러분, 내 앱을 통해 모든 수신 전화에 답변하기 위해 Android 앱을 만들고 있습니다. 나는 아래 lolipop뿐만 아니라 마시 멜로를 위해 그렇게 할 이상, 전 R & D 많이했지만 어떤 만족 해결책을 발견하지 않은, 그래서 코드 아래 자신의marshmallow 이상의 Android 기기에서 프로그래밍 방식으로 수신 전화에 응답하는 방법은 무엇입니까? (보안 패치 업데이트 날짜 1/09/16 이상)

위 마시멜로와 작동하지 않는 내에서 요구하고 있습니다. 이 코드는 Lolipop까지 작동합니다.

private void acceptCall_n() { 

      // for HTC devices we need to broadcast a connected headset 
      boolean broadcastConnected = MANUFACTURER_HTC.equalsIgnoreCase(Build.MANUFACTURER) 
        && !audioManager.isWiredHeadsetOn(); 



      if (broadcastConnected) { 
       broadcastHeadsetConnected(false); 
      } 

      try { 

       try { 
        // logger.debug("execute input keycode headset hook"); 
        Runtime.getRuntime().exec("input keyevent " + 
          Integer.toString(KeyEvent.KEYCODE_HEADSETHOOK)); 


       } catch (IOException e) { 

        Log.e("Call Exception ",e.toString()); 
        HelperMethods.showToastS(getBaseContext(),"Call Exception one "+e.toString()); 
        // Runtime.exec(String) had an I/O problem, try to fall back 
        // logger.debug("send keycode headset hook intents"); 
        String enforcedPerm = "android.permission.CALL_PRIVILEGED"; 
        Intent btnDown = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
          Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, 
            KeyEvent.KEYCODE_HEADSETHOOK)); 
        Intent btnUp = new Intent(Intent.ACTION_MEDIA_BUTTON).putExtra(
          Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, 
            KeyEvent.KEYCODE_HEADSETHOOK)); 

        sendOrderedBroadcast(btnDown, enforcedPerm); 
        sendOrderedBroadcast(btnUp, enforcedPerm); 
       } 
      }catch (Exception e){ 
       e.printStackTrace(); 
       Log.e("Call Exception two",e.toString()); 
       HelperMethods.showToastS(getBaseContext(),"Call Exception two "+e.toString()); 
      }finally { 
       if (broadcastConnected) { 
        broadcastHeadsetConnected(false); 
       } 
      } 
     } 

답변

0

나는 같은 문제에 직면했다. 근본적인 원인은 실행 명령이 SELinux 규칙에 의해 허용되지 않는다는 것입니다. this 솔루션을 사용해보십시오. 안드로이드 마쉬멜로 우에서 테스트 해봤습니다.

+0

https://stackoverflow.com/help/how-to-answer 필기 품질 답변을 참조하십시오. – jagapathi

관련 문제