【发布时间】: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 文档中的电子表格中,有没有更适合您的方法?