我想從兩個按鈕啓動和停止廣播接收器。 我已經在兩個按鈕監聽器中編寫了代碼。啓動和停止廣播接收器
的代碼如下: -
在startButton我已經寫的代碼如下
startCallBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
startCallBtn.setVisibility(View.INVISIBLE);
stopCallBtn.setVisibility(View.VISIBLE);
//register call receiver.
registerReceiver(callReceiver, new IntentFilter(
"android.intent.action.CALL"));
System.out.println("Registered Call Receiver Perfectly");
}
});
在我已經寫呼籲停止接收機
停止按鈕註冊接收機stopCallBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
stopCallBtn.setVisibility(View.INVISIBLE);
startCallBtn.setVisibility(View.VISIBLE);
stopService(new Intent(MainActivity.this, SpeakOut.class));
FileOutputStream fos;
//Unregister sms receivers
unregisterReceiver(callReceiver);
System.out.println("Unregistered Call Broadcast Receiver");
}
});
收聽新電話時仍有收聽者打電話
你把這個接收器還的Manifest.xml? –