慕莱坞森
我也在努力(在这里理解你可能是错误的)。您想要实现的是在Android 4.2(Jelly Bean)中显示该活动。我只是延迟显示活动。我在其他类中使用过PhoneStateListener。我可以在呼叫者屏幕上显示新活动。这是我的完整代码:文件MyBroadcastReceiver.javapublic class MyBroadcastReceiver extends BroadcastReceiver { static CustomPhoneStateListener phoneStateListener; Context context; Intent intent; @Override public void onReceive(Context context, Intent intent) { this.context = context; this.intent = intent; // TODO Auto-generated method stub TelephonyManager telephonyManager = (TelephonyManager) context .getSystemService(Context.TELEPHONY_SERVICE); phoneStateListener = new CustomPhoneStateListener(context); telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); }}文件CustomPhoneStateListener.javapublic class CustomPhoneStateListener extends PhoneStateListener { // private static final String TAG = "PhoneStateChanged"; Context context; // Context to make Toast if required private AudioManager amanager; Intent i1; public CustomPhoneStateListener(Context context) { super(); this.context = context; i1 = new Intent(context, YourActivity.class); i1.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); i1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); } @Override public void onCallStateChanged(int state, String incomingNumber) { super.onCallStateChanged(state, incomingNumber); switch (state) { case TelephonyManager.CALL_STATE_IDLE: Toast.makeText(context, "Phone state Idle", Toast.LENGTH_LONG) .show(); break; case TelephonyManager.CALL_STATE_OFFHOOK: Toast.makeText(context, "Phone state Off hook", Toast.LENGTH_LONG) .show(); break; case TelephonyManager.CALL_STATE_RINGING: try { Thread.sleep(3000); context.startActivity(i1); } catch (Exception e) { e.getLocalizedMessage(); } default: break; } }和YourActivity将保留为您创建的样子。注意:在此代码中,我也遇到了一些问题,它们位于此处。当关闭的呼叫关闭(未接呼叫或拒绝)时,活动未关闭。我无法点击“活动”(我想为我的应用添加一个按钮)它只能在第一次使用。当我第二次打电话时,我的应用程序停止了(我认为这是因为通话被拒时,Activity没有关闭)(接受了这些问题的帮助。谢谢。可能会帮助一些人)更新这是小演示如何实现此目标的链接。当关闭的呼叫关闭(未接呼叫或拒绝)时,活动未关闭。- 解决了我无法点击“活动”(我想为我的应用添加一个按钮)-已解决它只能在第一次使用。当我第二次打电话时,我的应用程序停止了(我认为这是因为通话被拒时,Activity没有关闭)-已解决