Hi everyone I am creating an android program where I am to make a phone call from a list of numbers in an array. Depending on the button click it will select the appropriate array. I can make the phone dial however my program force closes. This is bad because I need a dialog box to pop up afterwards (that portion of which I have completed but with no way to tell) I increments inside of the method for the dialog box, I can post it if you guys ned it. Here is what I have:
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();
}
I took the code that you gave and replaced the one I had in the manifest before. I can post it again if you think it would help!