Я пытаюсь реализовать фоновый сервис для передачи журналов из базы данных calllog на сервер, и я перепробовал много вещей ... таймер, поток, бесконечный цикл ... но, похоже, ничего не работает ... следующая программа может быть циклом таймера ... но оба из них не работают на некоторых телефонах ... Обе реализации следуют той же методологии, но разной реализации (очевидно) ... поэтому мой вопрос: я НЕ проверять некоторые условия, которые вызывают эту ошибку невозможности отправки данных .... Я понимаю, что данные перестают отправлять, когда они находятся в спящем режиме, но почти все телефоны возобновляют передачу данных, но некоторые не ...
Структура программирования.
public class BootableService extends Service{
@Override
public IBinder onBind(final Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
// use this to start my infinite thread here which is initialised inside this service class
}
@Override
public void onStart(final Intent intent, final int startId) {
//Use this to start a telophony listener that respond to call state and add the call from the call log to a blocking queue ....
telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// Create a new PhoneStateListener
listener = new PhoneStateListener() {
@Override
public void onCallStateChanged(int state, String incomingNumber) {
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:
System.out.println("phone IDLE");
// calls a function to add the events to a queue. that have not been sent already.
addtoQueue();
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
System.out.println("Phone in use");
break;
case TelephonyManager.CALL_STATE_RINGING:
System.out.println("Phone Ringing");
break;
}
}
};
// Register the listener wit the telephony manager
telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);
}
addToQueue()
{
//add to the queue add the call log not already transmitted to the server.
}
class handler HandleStuff{
this handles the data coming from the thread .,,,, the ID of the record sent. straight from the Android call log database. and store it.
}
Class ThreadRunning extends thread{
run(){
while(true){
// This implements take the elements from the queue if present
transmit 1 record///
sleep(20 seconds.)
}
}
}
}
логика срабатывает только один раз. когда телефон запускается или когда приложение установлено / открыто. если сервис еще не открыт.