-1

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!

smithseanp16
  • 15
  • 1
  • 6
  • 3
    You need to include, at a minimum, the stack dump that accompanies your force close. You should also include the relevant code it refers to. Without at least that level of info, instead of posting on stackoverflow you might consider posting on crystalball. – mah Oct 31 '11 at 14:45
  • I am trying to use the ARCA application to get my crash into a spreadsheet on my google docs, is there a way that would be better for you? – smithseanp16 Oct 31 '11 at 16:08

1 Answers1

0

I bet your manifest has this <receiver android:name="first.Package.localactivity">

But it actually does not exist. You might have spelt something wrong.

The problem is that you have and activity <activity android:name=".localactivity" and a broadcast receiver <receiver android:name=".localactivity"> with the same name. The android:name tag is used to identify the java file containing the Broadcast receiver.

Follow this tutorial


For your other question in the comments refer to this

Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Reno
  • 33,594
  • 11
  • 89
  • 102
  • Hey Reno this is the receiver I have: – smithseanp16 Nov 01 '11 at 16:08
  • It is It is. I really appreciate your help I am literally lost. Is there anything I can show you? – smithseanp16 Nov 01 '11 at 17:17
  • Edit your question and put in your manifest and the broadcast receiver code. Also if the manifest is taking too much of your time, you can directly do this `IntentFilter filter = new IntentFilter();` `filter.setAction("android.intent.action.PHONE_STATE");registerReceiver(receiver, filter);` i.e register your receiver dynamically – Reno Nov 01 '11 at 17:47
  • OK I will add the manifest, you wouldn't know how to add the broadcast receiver code would you? – smithseanp16 Nov 01 '11 at 18:40
  • Reno that didn't do it I have edited my question and included the portion you have added and added my manifest...thanks again for all your help! – smithseanp16 Nov 02 '11 at 18:15
  • Also since I am dialing within the application and not receiving any calls just wanted for the call I dialed to end do I still need a broadcast receiver? I guess I am just unsure of the structure this needs to be – smithseanp16 Nov 02 '11 at 19:13