【问题标题】:Android Force Close after initiating dial in a programAndroid 在程序中启动拨号后强制关闭
【发布时间】:2011-10-31 14:43:09
【问题描述】:

大家好,我正在创建一个 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();
      }

我使用了您提供的代码并替换了我之前在清单中的代码。如果你觉得有帮助,我可以再发一次!

【问题讨论】:

  • 您至少需要包含伴随您的强制关闭的堆栈转储。您还应该包括它引用的相关代码。如果没有至少该级别的信息,您可以考虑在水晶球上发帖,而不是在 stackoverflow 上发帖。
  • 我正在尝试使用 ARCA 应用程序将我的崩溃记录到我的 google 文档中的电子表格中,有没有更适合您的方法?

标签: java android


【解决方案1】:

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

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

问题是你有一个同名的活动<activity android:name=".localactivity" 和一个广播接收器<receiver android:name=".localactivity">android:name 标签用于标识包含广播接收器的 java 文件。

关注this tutorial


对于您在 cmets 中的其他问题refer to this

【讨论】:

  • 嘿 Reno,这是我的接收器:
  • 它就是它。我真的很感谢你的帮助,我真的迷路了。有什么可以给你看的吗?
  • 编辑您的问题并放入您的清单和广播接收器代码。此外,如果清单占用您太多时间,您可以直接执行此操作 IntentFilter filter = new IntentFilter(); filter.setAction("android.intent.action.PHONE_STATE");registerReceiver(receiver, filter); 即动态注册您的接收器
  • 好的,我会添加清单,你不会知道如何添加广播接收器代码吧?
  • Reno 没有这样做我已经编辑了我的问题并包括了您添加的部分并添加了我的清单...再次感谢您的所有帮助!
猜你喜欢
  • 1970-01-01
  • 2011-02-10
  • 2017-02-23
  • 2013-10-01
  • 1970-01-01
  • 2012-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多