@Override
public void onReceive(final Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
Log.d(TAG, "Call received: "+incomingNumber);
if (!incomingNumber.isEmpty()) {
WritableNativeMap params = new WritableNativeMap();
params.putString("app", "phone");
params.putString("text", incomingNumber);
NotificationModule.sendEvent("notificationReceived", params);
}
}
}, PhoneStateListener.LISTEN_CALL_STATE);
}
java类android.telephony.PhoneStateListener的实例源码
CallListener.java 文件源码
项目:things-notification
阅读 16
收藏 0
点赞 0
评论 0
ScreenListenerService.java 文件源码
项目:LockActivity
阅读 15
收藏 0
点赞 0
评论 0
private void listenTelephonyState() {
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(new PhoneStateListener(){
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state){
case TelephonyManager.CALL_STATE_IDLE:
//空闲
break;
case TelephonyManager.CALL_STATE_RINGING:
//响铃
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
//挂机
break;
}
}
},PhoneStateListener.LISTEN_CALL_STATE);
}
CellTracker.java 文件源码
项目:Android-IMSI-Catcher-Detector
阅读 25
收藏 0
点赞 0
评论 0
/**
* Start FemtoCell detection tracking (For CDMA Devices ONLY!)
*/
public void startTrackingFemto() {
/* Check if it is a CDMA phone */
if (device.getPhoneId() != TelephonyManager.PHONE_TYPE_CDMA) {
Helpers.msgShort(context, context.getString(R.string.femtocell_only_on_cdma_devices));
return;
}
trackingFemtocell = true;
mPhoneStateListener = new PhoneStateListener() {
public void onServiceStateChanged(ServiceState s) {
log.debug(context.getString(R.string.service_state_changed));
getServiceStateInfo(s);
}
};
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE);
setNotification();
}
MapViewerOsmDroid.java 文件源码
项目:Android-IMSI-Catcher-Detector
阅读 20
收藏 0
点赞 0
评论 0
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
log.info("Starting MapViewer");
setUpMapIfNeeded();
mDbHelper = new RealmHelper(this);
tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Bind to LocalService
Intent intent = new Intent(this, AimsicdService.class);
bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION |
PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
}
AnnouncementPeriodicTaskTest.java 文件源码
项目:mytracks
阅读 17
收藏 0
点赞 0
评论 0
public void testRun_ringWhileSpeaking() throws Exception {
startTask(TextToSpeech.SUCCESS);
expect(tts.isSpeaking()).andStubReturn(true);
expect(tts.stop()).andReturn(TextToSpeech.SUCCESS);
AndroidMock.replay(tts);
// Update the state to ringing - this should stop the current announcement.
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
// Run the announcement - this should do nothing.
task.run(null);
AndroidMock.verify(mockTask, tts);
}
BlacklistInterceptService.java 文件源码
项目:MobileGuard
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void onCreate() {
super.onCreate();
// System.out.println("BlacklistInterceptService onCreate");
// register call listener
telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
// register sms receiver
smsReceiver = new SmsReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(Constant.ACTION_SMS_RECEIVED);
// set max priority
filter.setPriority(Integer.MAX_VALUE);
// register
registerReceiver(smsReceiver, filter);
}
MainActivity.java 文件源码
项目:mobility-logger
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void onResume(){
super.onResume();
// Wifi broadcast Receiver
wifiReceiver = new WifiReceiver();
registerReceiver(wifiReceiver, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
wifiManager.startScan();
// Location Manager and Listener
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minimumSeconds * 1000, minimumDistance, locationListener);
// Telephony Manager and Listener
wakeLock.acquire();
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CELL_LOCATION |
PhoneStateListener.LISTEN_DATA_ACTIVITY | PhoneStateListener.LISTEN_DATA_CONNECTION_STATE |
PhoneStateListener.LISTEN_SERVICE_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTHS
| PhoneStateListener.LISTEN_CALL_STATE);
// Phone and SIM information are static, i.e. not updated regularly but only here
updatePhoneSimInfo();
}
AudioManager.java 文件源码
项目:QuranAndroid
阅读 32
收藏 0
点赞 0
评论 0
/**
* Listener to check incoming call
*/
private void initPhoneListener() {
final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
pauseMedia();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
isInCall = false;
if (isFirstStart == false) {
if (Build.VERSION.SDK_INT >= 17.0) {
bigNotification = true;
largeMediaPlayer = LargeMediaPlayer.getInstance(context);
} else {
bigNotification = false;
smallMediaPlayer = SmallMediaPlayer.getInstance(context);
}
resumeMedia();
}
isFirstStart = false;
}
super.onCallStateChanged(state, incomingNumber);
}
};
telephoneManger = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephoneManger != null) {
telephoneManger.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
AudioManager.java 文件源码
项目:QuranAndroid
阅读 31
收藏 0
点赞 0
评论 0
/**
* Listener to check incoming call
*/
private void initPhoneListener() {
final PhoneStateListener phoneStateListener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (state == TelephonyManager.CALL_STATE_RINGING) {
pauseMedia();
} else if (state == TelephonyManager.CALL_STATE_IDLE) {
isInCall = false;
if (isFirstStart == false) {
if (Build.VERSION.SDK_INT >= 17.0) {
bigNotification = true;
largeMediaPlayer = LargeMediaPlayer.getInstance(context);
} else {
bigNotification = false;
smallMediaPlayer = SmallMediaPlayer.getInstance(context);
}
resumeMedia();
}
isFirstStart = false;
}
super.onCallStateChanged(state, incomingNumber);
}
};
telephoneManger = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
if (telephoneManger != null) {
telephoneManger.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}
}
AudioTrackPlayerImpl.java 文件源码
项目:dcs-sdk-java
阅读 22
收藏 0
点赞 0
评论 0
public AudioTrackPlayerImpl() {
// init
initAudioTrack(AUDIO_FORMAT_PCM8K, 1);
// 读取音量和静音的数据
currentVolume = (float) MediaPlayerPreferenceUtil.get(context,
KEY_SP_VOLUME, 0.8f);
isMute = (boolean) MediaPlayerPreferenceUtil.get(context,
KEY_SP_MUTE, false);
// LinkedList
mediaPlayerListeners = Collections.synchronizedList(new LinkedList<IMediaPlayerListener>());
// 来电监听
telephonyManager = (TelephonyManager)
context.getSystemService(Service.TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
}