我正在开发一个应用程序,该应用程序需要在第一次通话后启动意图 - 但不是在每次通话后。
以下来源应在通话后启动意图 - 但如何将其修改为仅执行一次(在第一次通话后)而不是在每次通话后?
资源:
case TelephonyManager.CALL_STATE_RINGING:
Toast.makeText( context, "incoming call", Toast.LENGTH_LONG).show();
IntentService = new Intent(context, PlayService.class).setAction("incoming_call");
IntentService.putExtra("phone_number",intent.getStringExtra(TelephonyManager.EXTRA_INCOMING_NUMBER) );
if (SmsReceiver.bool)
context.startService(IntentService);
break;
或者我可以使用:
EndCallListener callListener = new EndCallListener();
TelephonyManager mTM = (TelephonyManager)this.getSystemService(Context.TELEPHONY_SERVICE);
mTM.listen(callListener, PhoneStateListener.LISTEN_CALL_STATE);
private class EndCallListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if(TelephonyManager.CALL_STATE_RINGING == state) {
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if(TelephonyManager.CALL_STATE_OFFHOOK == state) {
//wait for phone to go offhook (probably set a boolean flag) so you know your app initiated the call.
Log.i(LOG_TAG, "OFFHOOK");
}
if(TelephonyManager.CALL_STATE_IDLE == state) {
//when this state occurs, and your flag is set, restart your app
Log.i(LOG_TAG, "IDLE");
}
}
}