2015-11-06 74 views
0

我有問題。 我讀了很多教程,解釋如何讀取call.log,但我的問題是我怎麼能把呼叫日誌讀取器放入一個服務來檢測變化? 當進入通話記錄時,我的應用程序必須執行一些操作纔能有新的傳出呼叫。有人能幫我嗎? 問候呼叫日誌檢測正在更改

回答

0

如果要檢測來電,你要播出的操作: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" />