通话记录检测变化
Call log detect changing
我有一个问题。
我阅读了很多解释如何阅读 call.log 的教程,但我的问题是如何将呼叫日志 reader 放入服务中以检测变化?
当通话记录中有新的拨出电话时,我的应用程序必须执行一些操作。有人能帮我吗?
问候
如果你想检测来电,你必须广播动作:ACTION_PHONE_STATE_CHANGED
如果你想在服务中启动广播:
public class ServDelLog extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("SERVICE", "STARTED");
//-- Here is the filter
IntentFilter filter = new IntentFilter();
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
filter.setPriority(-1);
registerReceiver(receiver, filter);
//-- Inser your Code here ----
ScanCallLog(this); //-- For exapmle a function for scaning the log
//
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
Log.d("SERVICE", "STOPPED");
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED)){
//-- Because you've got to wait before the phone write into the call log
new CountDownTimer(5000, 1000) {
public void onFinish() {
ScanCallLog(context);
}
public void onTick(long millisUntilFinished) {
// millisUntilFinished The amount of time until finished.
}
}.start();
}
}
};
}
可以在您的 activity 中设置服务,方法是调用:
startService(new Intent(this, ServDelLog.class));
并且不要忘记在您的清单中添加:
<service android:name=".ServDelLog" />
我有一个问题。 我阅读了很多解释如何阅读 call.log 的教程,但我的问题是如何将呼叫日志 reader 放入服务中以检测变化? 当通话记录中有新的拨出电话时,我的应用程序必须执行一些操作。有人能帮我吗? 问候
如果你想检测来电,你必须广播动作:ACTION_PHONE_STATE_CHANGED
如果你想在服务中启动广播:
public class ServDelLog extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d("SERVICE", "STARTED");
//-- Here is the filter
IntentFilter filter = new IntentFilter();
filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
filter.setPriority(-1);
registerReceiver(receiver, filter);
//-- Inser your Code here ----
ScanCallLog(this); //-- For exapmle a function for scaning the log
//
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
unregisterReceiver(receiver);
Log.d("SERVICE", "STOPPED");
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
String action = intent.getAction();
if(action.equals(android.telephony.TelephonyManager.ACTION_PHONE_STATE_CHANGED)){
//-- Because you've got to wait before the phone write into the call log
new CountDownTimer(5000, 1000) {
public void onFinish() {
ScanCallLog(context);
}
public void onTick(long millisUntilFinished) {
// millisUntilFinished The amount of time until finished.
}
}.start();
}
}
};
}
可以在您的 activity 中设置服务,方法是调用:
startService(new Intent(this, ServDelLog.class));
并且不要忘记在您的清单中添加:
<service android:name=".ServDelLog" />