谢谢你的帮助.
码:
接收器的清单条目:
<receiver androID:name="liveForever" androID:label="NetworkChangeReceiver" > <intent-filter> <action androID:name="androID.net.conn.CONNECTIVITY_CHANGE" /> <action androID:name="androID.net.wifi.WIFI_STATE_CHANGED" /> </intent-filter></receiver>
接收器本身:
public static final int TYPE_WIFI = 1;public static final int TYPE_MOBILE = 2;public static final int TYPE_NOT_CONNECTED = 0;public static final String PREFS_name = "cakecloudpreferences";@OverrIDepublic voID onReceive(Context context,Intent intent) { SharedPreferences settings = context.getSharedPreferences(PREFS_name,0); if (getConnectivityStatus(context)!=0&&!settings.getBoolean("osmframerunning",false)) { context.stopService(new Intent(context,OSMFrame.class)); settings.edit().putBoolean("osmframerunning",false).commit(); Intent frameintent = new Intent(context,OSMFrame.class); frameintent.putExtra("username",settings.getString("usr","")); frameintent.putExtra("password",settings.getString("pswd","")); frameintent.putExtra("uID",settings.getString("uID","")); context.startService(frameintent); Log.i("ccliveForever","liveForever Triggered,OSMFrame restarted."); }}public int getConnectivityStatus(Context context) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); if (null != activeNetwork) { if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI) return TYPE_WIFI; if(activeNetwork.getType() == ConnectivityManager.TYPE_MOBILE) return TYPE_MOBILE; } return TYPE_NOT_CONNECTED;}
我列出的相关权限:
> androID.permission.ACCESS_WIFI_STATE
> androID.permission.ACCESS_NETWORK_STATE
> androID.permission.INTERNET
再次谢谢你!
解决方法 仅当启用或禁用WiFi时才会发送androID.net.wifi.WIFI_STATE_CHANGED.如果您希望在连接到WiFi网络或从WiFi网络断开连接时接收广播事件,则还需要捕获androID.net.wifi.STATE_CHANGE. 总结以上是内存溢出为你收集整理的android.net.wifi.WIFI_STATE_CHANGED没有播出全部内容,希望文章能够帮你解决android.net.wifi.WIFI_STATE_CHANGED没有播出所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)