可能重复:
Pass a value from activity to broadcastreceiver and start a service from the broadcast receiver
我创建了一个应用程序,用于将来电号码发送到蓝牙,我希望将活动管理员号码从活动传递给接收者。我怎么能这样做?
public void onResume() {
super.onResume();
registerReceiver(new IncomingCallReceiver(), new intentFilter("android.intent.action.PHONE_STATE"));
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
String msg2 = intent.getStringExtra("admin_no");
if(null == bundle)
return;
Log.i("IncomingCallReceiver",bundle.toString());
String state = bundle.getString(TelephonyManager.EXTRA_STATE);
Log.i("IncomingCallReceiver","State: "+ state);
if(state.equalsIgnoreCase(TelephonyManager.EXTRA_STATE_RINGING))
{
String phonenumber = bundle.getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
答案 0 :(得分:0)
试过这样的事情?
Intent intent = new Intent("android.intent.action.PHONE_STATE");
intent.putExtra("admin_no","9999999"); // change number here.
sendBroadcast(intent);