Mac Systems
- Forum-Beiträge: 1.727
22.07.2009, 17:47:19 via Website
22.07.2009 17:47:19 via Website
Hallo,
in meinen Service benutzt Ich folgenden Task:
Starte Ich Anfangs die APP im Emulator und das Netzwerk ist nicht erreichbar bekomme Ich die Meldung "Network not reachable. Waiting". Gebe Ich allerdings das Netzwerk Frei lädt er zwar über das Netzwerk Daten nach, allerdings wird nach einer weiteren Speere des Netzwerkes nicht mehr das "Network not reachable. Waiting." ausgegeben. Sperre Ich das Netzwerk ist folgendes zu lesen:
Anhand der Ausgaben schließe Ich darauf das dass Netzwerk irgendwo blockiert, sollte Ich dann nicht aber irgendwo eine IOException zu Gesicht bekommen (ja, ich logge diese alle) ?
Zum weiteren Verständnis des Codes noch folgende Methode:
Wer hat nen Tip für nen Anfänger ? Oder wie Debugge Ich so was auf Android ?
Danke,
Mac
in meinen Service benutzt Ich folgenden Task:
1private TimerTask spotUpdateTask = new TimerTask()
2 {
3
4 @Override
5 public void run()
6 {
7 final Intent intent = new Intent(DE_MACSYSTEMS_WINDROID_SPOT_UPDATE_ACTION);
8 if (!Util.isSpotConfigured(SpotService.this))
9 {
10 Log.i(LOG_TAG, "No spot configured.");
11 return;
12 }
13
14 if (IOUtils.isNetworkReachable(SpotService.this))
15 {
16
17 long start = System.currentTimeMillis();
18 final SpotConfigurationVO spot = Util.getSpotConfiguration(SpotService.this);
19 long end = System.currentTimeMillis();
20
21 try
22 {
23 final SpotForecastDetail update = SpotUpdater.getUpdate(spot);
24 }
25 catch (NullPointerException e)
26 {
27 Log.e(LOG_TAG, "Failed to update Spot.", e);
28 }
29 catch (IOException e)
30 {
31 Log.e(LOG_TAG, "Failed to update Spot.", e);
32 }
33
34 sendBroadcast(intent);
35 }
36 else
37 {
38 Log.d(LOG_TAG, "Network not reachable. Waiting.");
39 }
40
41 }
42 };
2 {
3
4 @Override
5 public void run()
6 {
7 final Intent intent = new Intent(DE_MACSYSTEMS_WINDROID_SPOT_UPDATE_ACTION);
8 if (!Util.isSpotConfigured(SpotService.this))
9 {
10 Log.i(LOG_TAG, "No spot configured.");
11 return;
12 }
13
14 if (IOUtils.isNetworkReachable(SpotService.this))
15 {
16
17 long start = System.currentTimeMillis();
18 final SpotConfigurationVO spot = Util.getSpotConfiguration(SpotService.this);
19 long end = System.currentTimeMillis();
20
21 try
22 {
23 final SpotForecastDetail update = SpotUpdater.getUpdate(spot);
24 }
25 catch (NullPointerException e)
26 {
27 Log.e(LOG_TAG, "Failed to update Spot.", e);
28 }
29 catch (IOException e)
30 {
31 Log.e(LOG_TAG, "Failed to update Spot.", e);
32 }
33
34 sendBroadcast(intent);
35 }
36 else
37 {
38 Log.d(LOG_TAG, "Network not reachable. Waiting.");
39 }
40
41 }
42 };
Starte Ich Anfangs die APP im Emulator und das Netzwerk ist nicht erreichbar bekomme Ich die Meldung "Network not reachable. Waiting". Gebe Ich allerdings das Netzwerk Frei lädt er zwar über das Netzwerk Daten nach, allerdings wird nach einer weiteren Speere des Netzwerkes nicht mehr das "Network not reachable. Waiting." ausgegeben. Sperre Ich das Netzwerk ist folgendes zu lesen:
07-22 17:19:28.630: DEBUG/GpsLocationProvider(588): state: DISCONNECTED apnName: epc.tmobile.com reason: gprsDetached
Anhand der Ausgaben schließe Ich darauf das dass Netzwerk irgendwo blockiert, sollte Ich dann nicht aber irgendwo eine IOException zu Gesicht bekommen (ja, ich logge diese alle) ?
Zum weiteren Verständnis des Codes noch folgende Methode:
1/**
2 * Returns <code>true</code> when Network is reachable and connected.
3 *
4 * @param _context
5 * @return
6 */
7 public static boolean isNetworkReachable(final Context _context)
8 {
9 final ConnectivityManager systemService = (ConnectivityManager) _context
10 .getSystemService(Context.CONNECTIVITY_SERVICE);
11
12 /**
13 * Avoid nullpointerexception when offline
14 */
15 if (systemService.getActiveNetworkInfo() == null)
16 {
17 return false;
18 }
19
20 final State networkState = systemService.getActiveNetworkInfo().getState();
21 return State.CONNECTED == networkState ? true : false;
22 }
2 * Returns <code>true</code> when Network is reachable and connected.
3 *
4 * @param _context
5 * @return
6 */
7 public static boolean isNetworkReachable(final Context _context)
8 {
9 final ConnectivityManager systemService = (ConnectivityManager) _context
10 .getSystemService(Context.CONNECTIVITY_SERVICE);
11
12 /**
13 * Avoid nullpointerexception when offline
14 */
15 if (systemService.getActiveNetworkInfo() == null)
16 {
17 return false;
18 }
19
20 final State networkState = systemService.getActiveNetworkInfo().getState();
21 return State.CONNECTED == networkState ? true : false;
22 }
Wer hat nen Tip für nen Anfänger ? Oder wie Debugge Ich so was auf Android ?
Danke,
Mac
— geändert am 22.07.2009, 17:48:38
Windmate HD, See you @ IO 14 , Worked on Wundercar, Glass V3, LG G Watch, Moto 360, Android TV
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.