android-ibc-forum

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b2ac5a22a1c3c74bdd85609b9ee098c920c16566
parent f2a57cfd19a590123b03480f7d6cb23ecca17e4e
Author: Jan Dankert <devnull@localhost>
Date:   Mon,  6 Feb 2012 22:02:19 +0100

Receiver für den Netzwerk-Status.

Diffstat:
AndroidManifest.xml | 16++++++++++++----
src/de/mtbnews/android/receiver/NetworkStateReceiver.java | 31+++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/AndroidManifest.xml b/AndroidManifest.xml @@ -2,8 +2,8 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="4" android:versionName="1.3" package="de.mtbnews.android"> - <application android:icon="@drawable/ibc_icon" android:name=".IBCApplication" - android:label="@string/app_name"> + <application android:icon="@drawable/ibc_icon" + android:name=".IBCApplication" android:label="@string/app_name"> <activity android:name=".IBCActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -35,8 +35,10 @@ <activity android:name="ReplyMailActivity" android:label="@string/reply"></activity> <activity android:name="ReplyPostActivity" android:label="@string/reply"></activity> <activity android:name="CreateTopicActivity" android:label="@string/new_topic"></activity> - <activity android:name="SubscriptionForenActivity" android:label="@string/subscription_forums"></activity> - <activity android:name="SubscriptionTopicsActivity" android:label="@string/subscription_topics"></activity> + <activity android:name="SubscriptionForenActivity" + android:label="@string/subscription_forums"></activity> + <activity android:name="SubscriptionTopicsActivity" + android:label="@string/subscription_topics"></activity> <!-- declare the default searchable Activity for the whole app --> <meta-data android:name="android.app.default_searchable" @@ -46,6 +48,12 @@ </application> + <receiver class=".receiver.NetworkStateReceiver" android:name="NetworkStateReceiver"> + <intent-filter> + <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> + </intent-filter> + </receiver> + <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> diff --git a/src/de/mtbnews/android/receiver/NetworkStateReceiver.java b/src/de/mtbnews/android/receiver/NetworkStateReceiver.java @@ -0,0 +1,30 @@ +package de.mtbnews.android.receiver; + +import de.mtbnews.android.service.SubscriptionService; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.net.ConnectivityManager; +import android.util.Log; + +public class NetworkStateReceiver extends BroadcastReceiver +{ + + @Override + public void onReceive(Context context, Intent intent) + { + boolean noConnectivity = intent.getBooleanExtra( + ConnectivityManager.EXTRA_NO_CONNECTIVITY, false); + if (!noConnectivity) + { + Log.d("IBC", "connection lost, stopping service"); + context.stopService(new Intent(context, SubscriptionService.class)); + } + else + { + Log.d("IBC", "connection established, starting service"); + context + .startService(new Intent(context, SubscriptionService.class)); + } + } +}+ \ No newline at end of file