Back to project page notify.
The source code is released under:
GNU General Public License
If you think the Android project notify listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.example.notify; // w ww.j a va2s.c o m import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.BatteryManager; import org.json.JSONObject; public class IntentBroadcastReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { String action = intent.getAction(); if (action == "android.intent.action.BATTERY_CHANGED") { if (MainActivity.ma != null) { String batteryStatus = String.valueOf(intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)); try { JSONObject message = new JSONObject(); message.put("type", "battery"); JSONObject message1 = new JSONObject(); message1.put("percent", batteryStatus); message.put("arguments", message1); MainActivity.ma.ba.sendToServer(message.toString()); } catch (Exception e) { } } } else if (action == "android.net.conn.CONNECTIVITY_CHANGE") { if (MainActivity.ma == null) { return; } ConnectivityManager cn = (ConnectivityManager)MainActivity.ma.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo ni = cn.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if (ni != null && ni.isConnected()) { if (MainActivity.ma.isOpen) { MainActivity.df.displayConnect(); } } else { if (MainActivity.ma.isOpen) { MainActivity.df.displayWifiWarning(); try { BackgroundService.dis.close(); } catch (Exception e) { } } } } } }