我创建了一个应用程序,用于将来电号码发送到蓝牙工作正常。现在我想将管理员号码用户从活动传递给接收者。我该怎么做?我尝试了一些东西,但我的 apk 崩溃了......在添加了传递变量方法之后.. .如果管理员呼叫,我想发送 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();
}
}