android - my app with broadcast receiver and wifi -


i, firt app android , i'm trying comunicate hardware because me it's exciting!

when disable wifi or change network.... need make toast , vibrate. what's wrong???

i test app galaxy s2 4.1.2 want app able run on old phones android 2.3.3.

androidmanifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="dado.wifibc" android:versioncode="1" android:versionname="1.0" >  <uses-sdk     android:minsdkversion="8"     android:targetsdkversion="19" /> <uses-permission android:name="android.permission.access_wifi_state"/> <uses-permission android:name="android.permission.access_network_state"/> <uses-permission android:name="android.permission.change_network_state"/> <uses-permission android:name="android.permission.change_wifi_state"/> <uses-permission android:name="android.permission.vibrate"/>  <application     android:allowbackup="true"     android:icon="@drawable/ic_launcher"     android:label="@string/app_name"     android:theme="@style/apptheme" >      <receiver          android:name="dado.wifibc.broadcastreceiver">         <intent-filter>             <action android:name="android.net.wifi.wifi_state_changed"/>             <action android:name="android.net.wifi.state_change"/>         </intent-filter>     </receiver> </application>  </manifest> 

broadcastreceiver.java

package dado.wifibc;  import android.content.broadcastreceiver; import android.content.context; import android.content.intent; import android.os.vibrator; import android.widget.toast;  public class broadcastreceiver extends broadcastreceiver {  @override public void onreceive(context context, intent intent) {     // todo auto-generated method stub     toast.maketext(context, "blablabla!!!.",toast.length_long).show();      // vibrate mobile phone     vibrator vibrator = (vibrator)   context.getsystemservice(context.vibrator_service);     vibrator.vibrate(2000); }  } 

pls, remove action intent filter , set action as"android.net.conn.connectivity_change" like,

      <receiver      android:name="dado.wifibc.broadcastreceiver">     <intent-filter>         <action android:name="android.net.conn.connectivity_change"/>      </intent-filter> 

and onreceive(),

           final connectivitymanager connmgr = (connectivitymanager) context                     .getsystemservice(context.connectivity_service);              final android.net.networkinfo wifi = connmgr                     .getnetworkinfo(connectivitymanager.type_wifi);                      if (!wifi.isavailable())              {                toast.maketext(context, "blablabla!!!.",toast.length_long).show();          // vibrate mobile phone          vibrator vibrator = (vibrator)   context.getsystemservice(context.vibrator_service);         vibrator.vibrate(2000);   } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -