启动拨号程序后,Android Force关闭

时间:2011-10-31 14:43:10

标签: java android

大家好我正在创建一个Android程序,我将从一个数组列表中拨打电话。根据按钮单击它将选择适当的数组。我可以打电话拨打我的程序强制关闭。这很糟糕,因为我需要一个对话框随后弹出(我已经完成但我无法分辨的那部分)我在对话框的方法内增加,我可以发布它,如果你们的话。这就是我所拥有的:

  public class ServiceReceiver extends BroadcastReceiver {
  public void onReceive(Context context, Intent intent) {
    MyPhoneStateListener phoneListener=new MyPhoneStateListener();
    TelephonyManager telephony = (TelephonyManager) 
    context.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(phoneListener,PhoneStateListener.LISTEN_CALL_STATE);
  }
}
public class MyPhoneStateListener extends PhoneStateListener {
  public void onCallStateChanged(int state,String incomingNumber){
      boolean mCall=false;
  switch(state){
    case TelephonyManager.CALL_STATE_IDLE:
      Log.d("DEBUG", "IDLE");
      if(mCall)
      {
        mCall=false; //Reverting the flag, indicating you are aware that there was call
        // Here do the rest of your operation you want
        showAlert();
      }
    break;
    case TelephonyManager.CALL_STATE_OFFHOOK:
      Log.d("DEBUG", "OFFHOOK");
      mCall=true;
    break;
    case TelephonyManager.CALL_STATE_RINGING:
      Log.d("DEBUG", "RINGING");
      mCall=true;
    break;
    }
  } 
}
 public void showAlert(){
      new AlertDialog.Builder( this )
         .setTitle( "Was This Call Sucessful?" )
         .setMessage( "Did you get through and is help on the way?" )
         .setPositiveButton( "Yes", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                 Log.d("AlertDialog", "Positive");
                 startActivity(new Intent("first.Package.HaitiDisasterPhoneAppActivity"));
             }  })
         .setNegativeButton( "No", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                 Log.d("AlertDialog","Negative");
                 i++;
                 sequence();
             } })
         .show();
      }

我拿了你给的代码,然后替换了清单中的代码。如果你觉得它会有所帮助,我可以再发一次!

1 个答案:

答案 0 :(得分:0)

我打赌你的清单有<receiver android:name="first.Package.localactivity">

但它实际上并不存在。你可能拼写错了。

问题在于您拥有和活动<activity android:name=".localactivity"以及具有相同名称的广播接收器<receiver android:name=".localactivity">android:name标记用于标识包含广播接收器的java文件。

关注this tutorial


评论refer to this

中的其他问题