-1
서비스에서 전화 상태 브로드 캐스트 수신기를 등록 및 등록 취소하려고 시도하지만 그 서비스가 실행되지 않았기 때문에 매니페스트에서도 전화 상태 권한을 선언했습니다.BraodCastReceiver가 전화 상태 수신기에 대해 실행되지 않습니다.
여기 내 방송 수신기입니다.
public class IncomingCalls extends BroadcastReceiver {
private static String mLastState;
@Override
public void onReceive(Context context, Intent intent) {
Log.i(ApplicationUtils.TAG, "IncomingCalls");
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
String phoneNumber = intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
if (!state.equals(mLastState)) {
mLastState = state;
Log.i(ApplicationUtils.TAG, state);
if (mLastState==TelephonyManager.EXTRA_STATE_RINGING) {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNumber, null, CallListenService.MESSAGE, null, null);
}
}
}
}
그리고 여기에 방송을 등록하고 등록을 취소하는 서비스가 있습니다. 내가 서비스를 그것은 전에 일하던
Intent intent1 = new Intent(context, CallListenService.class);
intent1.putExtra(KEY_MESSAGE, msg);
context.startService(intent1);
을 시작하지만 지금은 전혀 작동하지 않는 방법
public class CallListenService extends Service {
private static final String ACTION = "android.intent.action.PHONE_STATE";
static IncomingCalls myReceiver;
public static String MESSAGE;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
final IntentFilter theFilter = new IntentFilter();
theFilter.addAction(ACTION);
myReceiver = new IncomingCalls();
// Registers the receiver so that your service will listen for
// broadcasts
this.registerReceiver(myReceiver, theFilter);
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
MESSAGE = intent.getStringExtra(KEY_MESSAGE);
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
super.onDestroy();
// Do not forget to unregister the receiver!!!
this.unregisterReceiver(myReceiver);
}
}
는 점이다.
어디에서'startService()'를 호출합니까? – nandsito
을 다른 브로드 캐스트 리시버에 넣습니다. –