我有一个Broadcastreceiver来检测拨出电话何时结束。如果调用结束,我该如何编写一个返回布尔值的方法?

时间:2017-01-27 21:44:52

标签: android android-studio call android-broadcastreceiver phone-state-listener

我有以下 BroadcastReceiver 来检测拨出电话刚刚结束的时间:

public class MyPhoneReceiver extends BroadcastReceiver{

  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d("APP", "ACTION:" + intent.getAction());

    if (Intent.ACTION_NEW_OUTGOING_CALL.equals(intent.getAction())) {
      final String originalNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
      Log.d("APP", "outgoing,ringing:" + originalNumber);
    }
  }
}

我想编写一个布尔方法,如果调用刚刚结束则返回true,否则返回false。怎么可能?

public boolean callHasEnded {
  //what should I write here?
}

在清单中要明确我有以下内容:          

<uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />

<receiver android:name=".MyPhoneReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.NEW_OUTGOING_CALL" />
    </intent-filter>
</receiver>

提前感谢您的帮助!

0 个答案:

没有答案