I have a BroadcastReceiver that listens for the BOOT_COMPLETED, that
part works I know because I disabled my phone listener and displayed a
Toast within. That BroadcastReceiver is supposed to start a service,
that also works. I run into Force Close issues when my service
attempts to tell my TelephonyManager to listen.

Any one have any ideas? Here is my code

StartSeviceAtStartUp.java


import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;


public class StartSeviceAtStartUp extends BroadcastReceiver
{
        public void onReceive(Context context, Intent intent)
        {
          Intent serviceIntent = new Intent(context, listenService.class);
          context.startService(serviceIntent);
        }
}

listenService.java

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;

public class listenService extends Service
{

  @Override
  public void onCreate()
  {
    super.onCreate();
    TelephonyManager telMgr = (TelephonyManager) getSystemService
(Context.TELEPHONY_SERVICE);
        telMgr.listen(new CallStateListener(),
PhoneStateListener.LISTEN_CALL_STATE);
  }
  @Override
  public void onStart(Intent i, int startid)
  {

  }

  @Override
  public IBinder onBind(Intent arg0)
  {
        // TODO Auto-generated method stub
        return null;
  }
}

CallStateListener.java

package com.guysandroidstuff.fcallerid;

import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;

public class CallStateListener extends PhoneStateListener
{
  public void onCallStateChanged(int state, String incomingNumber)
  {
    super.onCallStateChanged(state, incomingNumber);
    switch(state)
    {
      case TelephonyManager.CALL_STATE_IDLE:
          Log.v("DEBUG", "IDLE YO");
          break;
      case TelephonyManager.CALL_STATE_OFFHOOK:
          Log.v("DEBUG", "OFF HOOK");
          break;
      case TelephonyManager.CALL_STATE_RINGING:
          Log.v("DEBUG", "RINGING YO");
          break;
    }
  }
}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to