【问题标题】:Call log detect changing通话记录检测变化
【发布时间】:2015-11-06 22:04:52
【问题描述】:

我有一个问题。 我阅读了很多解释如何阅读 call.log 的教程,但我的问题是如何将呼叫日志阅读器放入服务中以检测更改? 当进入通话记录有一个新的拨出电话时,我的应用程序必须执行一些操作。有人能帮我吗? 问候

【问题讨论】:

    标签: android logging service call


    【解决方案1】:

    如果你想检测来电,你必须广播动作: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();
    
                }
            }
        };
    }
    

    可以通过调用在你的活动中设置服务:

    startService(new Intent(this, ServDelLog.class));
    

    别忘了在清单中添加:

    <service android:name=".ServDelLog" />
    

    【讨论】:

      猜你喜欢
      • 2022-01-21
      • 1970-01-01
      • 2012-01-20
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多