2017-12-21 12 views
-1

나는 안드로이드에 처음 도움을 요청하십시오. 이 코드를 사용하여 시도
... 백그라운드 서비스에서 전화를 거는 방법은 무엇입니까?

Intent intent = new Intent(Intent.ACTION_CALL); 
intent.setData(Uri.parse("tel:" + number)); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.addFlags(Intent.FLAG_FROM_BACKGROUND); 
startActivity(intent); 

작동하지 않았다 : 그것은 갑자기 멈췄다.
필요한 사용 권한을 언급했습니다.

+0

https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare

+2

Welcome to StackOverflow! 문제를 해결할 수 있도록 자세한 내용을 제공해주십시오. [How to Ask] (https://stackoverflow.com/help/how-to-ask)도 참조하십시오. – Felix

답변

0

아래 코드를 시도하십시오.

 new Handler().post(new Runnable() { 
      @Override 
      public void run() { 
Intent intent = new Intent(Intent.ACTION_CALL); 
intent.setData(Uri.parse("tel:" + number)); 
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
intent.addFlags(Intent.FLAG_FROM_BACKGROUND); 
context.startActivity(intent); 
      } 
     }); 

당신은 서비스 onStart() 방법에서 컨텍스트를 얻을 것이다. InPlace Context은 사용할 수 있습니다 getApplicationContext()

관련 문제