Hello , I am trying to develop an application , which will use the internet throughout the application .The user will be informed when the internet disconnects or connects . I have searched a lot of codes and tried running them but I couldn't get them worked .Could anyone give me a hand to use static broadcast receivers? I am totally new to android .Any help is appreciated .Thank you .. Here one of the examples is : ******************************************************** <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.broadcastreceiver" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name=".MainActivity" android:label="@string/title_activity_main" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <receiver android:name="ConnectionChangeReceiver"> <intent-filter> <action android:name="com.example.broadcastreceiver"/> </intent-filter> </receiver> </application> </manifest> ******************************************************************************************** package com.example.broadcastreceiver; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.content.IntentFilter; import android.view.Menu;
public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Intent intent=new Intent(); intent.setAction("com.example.broadcastreceiver"); sendBroadcast(intent); } } ************************************************************************* package com.example.broadcastreceiver; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.widget.Toast; public class ConnectionChangeReceiver extends BroadcastReceiver { @Override public void onReceive( Context context, Intent intent ) { ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE ); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE ); if ( activeNetInfo != null ) { Toast.makeText( context, "Active Network Type : "+ activeNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show(); } if( mobNetInfo != null ) { Toast.makeText( context, "Mobile Network Type : "+ mobNetInfo.getTypeName(), Toast.LENGTH_SHORT ).show(); } } } ********************************** <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:padding="@dimen/padding_medium" android:text="@string/hello_world" tools:context=".MainActivity" /> </RelativeLayout> -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en