0

实际上,在我的应用程序中,我想在我的手机拨打任何电话时发送一条消息......这里的应用程序安装时间要求提供父母号码及其号码从我的第一个活动发送到广播接收器活动......它在那里接收到敬酒值..但是当我打电话时,它的值更改为null ...有人可以帮助我在电话通话时访问该值..有可能吗?如何..谢谢我的代码如下.. .

在我的第一个活动中向广播接收器发送值:

try
{
     Toast.makeText(getApplicationContext(), "try", Toast.LENGTH_LONG).show();

     Intent in = new Intent("my.action.string");
     in.putExtra("parent", PARENT);//this string sending to broadcast receiver
     sendBroadcast(in);
}
 catch (Exception e) 
 {
    // TODO: handle exception
     e.printStackTrace();
}          

我的广播接收器是:

public class myBroadcast extends BroadcastReceiver
{
    String out_number;
    String myparent;
    @Override
    public void onReceive(Context context, Intent intent) 
    {
        // TODO Auto-generated method stub
        myparent = intent.getExtras().getString("parent"); //this sting access the number first and then change to null at making phone call
        final String my=myparent;
        Toast.makeText(context, "broadcst"+myparent, Toast.LENGTH_LONG).show();

        if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL"))
        {
            out_number=intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
            Toast.makeText(context, "broadcst"+my+" "+out_number, Toast.LENGTH_LONG).show();
            SmsManager sm=SmsManager.getDefault();
            sm.sendTextMessage(myparent, "5554", "calling..to"+myparent, null, null); //5554 is my emulator number to check its in emulator
             Toast.makeText(context, "send"+out_number, Toast.LENGTH_SHORT).show();
        }
    }
}
4

1 回答 1

0
/*
 * The Receiver is intended for the incoming calls read though the phone
 * state for more details see android.content.BroadcastReceiver
 * 
 * @author parul
 * 
 */

public class InComingCallReciever extends BroadcastReceiver {

  public static String LOG = "InComingCall";

  /*
   * (The onReceive is invoked when we receive an arbitrary intent from the
   * Incoming call Service)
   * 
   * @see android.content.BroadcastReceiver#onReceive(android.content.Context,
   * android.content.Intent)
   */

  @Override
  public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub

    Log.v(LOG, "InComingCallReciever");

    Bundle bundle = intent.getExtras();
    if (bundle == null) {
      return;
    }
    String state = bundle.getString(TelephonyManager.EXTRA_STATE);
    Log.v(LOG, "" + state);

    if (state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING)) {
      String phoneNumber = bundle
          .getString(TelephonyManager.EXTRA_INCOMING_NUMBER);

      Toast.makeText(context, "The Incoming Number is ..." + phoneNumber,
          Toast.LENGTH_SHORT).show();
      Log.v(LOG, "incomming number is ... " + phoneNumber);
    } else {
      Log.v(LOG, "test 2 ");
    }
  }
}
于 2013-02-12T09:57:56.100 回答