我创建了一个应用程序,用于发送来电号码到蓝牙工作正常。现在我想要将管理员号码用户从活动传递到接收器。我怎么能这样做?我尝试了一些东西,但我的apk崩溃... 添加pass变量方法后......如果管理员调用,我想发送bt信号...
public void onResume() {
super.onResume();
registerReceiver(new IncomingCallReceiver(), new intentFilter("android.intent.action.PHONE_STATE"));
//Intent intent = new Intent("android.intent.action.PHONE_STATE");
//intent.putExtra("admin_no",strAdmin); // change number here.
//sendBroadcast(intent);
wl.acquire();
}
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
// String admin2 = 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);
Log.i("IncomingCallReceiver","Incomng Number: " + phonenumber);
String info = "Detect call... \nIncoming number: " + phonenumber;
Toast.makeText(context, info, Toast.LENGTH_LONG).show();
if(info.indexOf(admin)>0){
//Toast.makeText(context, "Alarm service!",Toast.LENGTH_LONG).show();
//Intent service = new Intent(context, Btservice.class);
//context.startService(service);
//String msg = intent.getStringExtra("data");
try {
//DetectCallBt.sendDataBT(bat);
Activity2.sendDataBT("1");
} catch (IOException e) {
//TODO Auto-generated catch block
e.printStackTrace();
}
}