Android Open Source - notify Intent Broadcast Receiver






From Project

Back to project page notify.

License

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.

Java Source Code

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) {

                    }
                }
            }
        }
    }
}




Java Source Code List

com.example.notify.AccessibilityListenerService.java
com.example.notify.BackgroundService.java
com.example.notify.Broadcast.java
com.example.notify.DisplayFragments.java
com.example.notify.EnumMessage.java
com.example.notify.FragmentAccessibility.java
com.example.notify.FragmentBroadcastReconnect.java
com.example.notify.FragmentConnect.java
com.example.notify.FragmentConnected.java
com.example.notify.FragmentConnecting.java
com.example.notify.FragmentManual.java
com.example.notify.FragmentNoQrcodeScanner.java
com.example.notify.FragmentQrcodeWrong.java
com.example.notify.FragmentReconnect.java
com.example.notify.FragmentWifiWarning.java
com.example.notify.IntentBroadcastReceiver.java
com.example.notify.MainActivity.java
com.example.notify.OurUtils.java