2017-11-03 14 views
1

私はAndroidアプリケーションでサービスを使用して、バックグラウンドでいくつかのコードを実行しています。アプリケーションがバックグラウンドになると、1分後に私のアプリケーションを通してコールを生成したい。電話機のロックが解除されたときにコールが生成されますが、電話機がロックされているときは生成されません。これを達成する方法は?電話がロックされているときに電話をかける方法は?

+0

は、あなたのサービスであることを確認してください:

 Intent callIntent = new Intent(Intent.ACTION_CALL); callIntent.setData(Uri.parse("tel:" + PhoneNO)); callIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (ActivityCompat.checkSelfPermission(SubscribersDetail.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. return; } startActivity(callIntent); 

もこれをチェックlogcatにメッセージを表示して画面が消えているときに実行します。 –

+0

はい画面がオフの場合、私のサービスが実行されています。 –

答えて

1

これにより、携帯電話の状態を確認します。その後、

DevicePolicyManager dpm = (DevicePolicyManager) 
context.getSystemService(Context.DEVICE_POLICY_SERVICE); 
dpm.lockNow(); 

と時間が打ち上げコールを完了したときにタイマーを使用します。 http://chandan-tech.blogspot.in/2010/10/handling-screen-lock-unlock-in-android.html

+0

ソリューションのおかげで... –

関連する問題