import java.util.Timer;
import java.util.TimerTask;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.PendingIntent.CanceledException;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;
public class FileScannerService extends Service implements ConstDaten
{
public static Main MAIN_ACTIVITY;
private Timer timer=new Timer();
private final IBinder fsBinder = new FsBinder();
private static final String LOG_TAG = FileScannerService.class.getSimpleName();
public static void setMainActivity(Main activity)
{
MAIN_ACTIVITY = activity;
}
public class FsBinder extends Binder {
FileScannerService getService() {
return FileScannerService.this;
}
}
public IBinder onBind(Intent intent) {
if(DEBUG)
Log.d(LOG_TAG, "FileService onBind!");
return fsBinder;
}
@Override
public void onCreate()
{
super.onCreate();
_startService();
if (MAIN_ACTIVITY != null) Log.d(getClass().getSimpleName(), "FileScannerService started");
//bprReciver
context = this;
mBroadcastReciver = new bprReciver();
context.registerReceiver(mBroadcastReciver, intentFilter);
}
@Override
public void onDestroy()
{
super.onDestroy();
_shutdownService();
if (MAIN_ACTIVITY != null) Log.d(getClass().getSimpleName(), "FileScannerService stopped");
}
/*
public static boolean toast = false;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if ((flags & START_FLAG_REDELIVERY) == 1) {
toast = true;
}
return 0;
};
*/
private void _startService()
{
timer.scheduleAtFixedRate(
new TimerTask() {
public void run() {
try{
doServiceWork();
Thread.sleep(UPDATE_INTERVAL_FS);
}catch(InterruptedException ie){
Log.e(getClass().getSimpleName(), "FileScannerService InterruptedException"+ie.toString());
}
}
},
DELAY_INTERVAL_FS,
UPDATE_INTERVAL_FS);
if(DEBUG)
Log.d(getClass().getSimpleName(), "FileScannerService Timer started....");
}
private bprReciver mBroadcastReciver;
private Context context = null;
private final IntentFilter intentFilter = new IntentFilter("url.ganzgegeim.BPR_INTENT");
//ID für Notivication 42
private String m_stg = "";
private boolean notifyOn = false;
private String bprText = "TEXT";
private String bprBlog = "";
private void doServiceWork()
{
//Abfrage ob Netzwerk aktiv
boolean state = GetNetworkStatus.isNetworkReachable(this, false);
if(state == false) {
m_stg = "";
bprText = "";
bprBlog = "";
processStopNotification(true);
return;
}
GetDownload gt = new GetDownload();
//Blog abholen
bprBlog = gt.DownloadText(BLOG, true);
//Banner apbholen
String str = gt.DownloadText(BANNER, false);
if(DEBUG)
Log.d(LOG_TAG, str+ " " + bprBlog);
bprText = str;
if((str.equals(m_stg)) && (str.length() > 3)) {
return;
}
if(str.length() > 3) {
Intent broadcastIntent = new Intent("url.ganzgegeim.BPR_INTENT");
broadcastIntent.putExtra("bprStrg", str);
context.sendBroadcast(broadcastIntent);
} else {
processStopNotification(false);
}
UpdateDataAndInformReceivers(str);
m_stg = str;
}
------------ schnipp
Ich vermute das der Fehler in diesem Teil steckt.
Gruß
Jürgen