2017-12-21 36 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-ha-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()

関連する問題