Android Open Source - android-weather-station Permission Broadcast Receiver






From Project

Back to project page android-weather-station.

License

The source code is released under:

Apache License

If you think the Android project android-weather-station 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 de.grundid.weather.io;
/*w  w  w.  j a  v  a 2 s.  c om*/
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.hardware.usb.UsbDevice;
import android.hardware.usb.UsbManager;
import android.util.Log;
import android.widget.Toast;
import de.grundid.weather.Constants;

public class PermissionBroadcastReceiver extends BroadcastReceiver {

  private AttachedDeviceHandler attachedDeviceHandler;

  public PermissionBroadcastReceiver(AttachedDeviceHandler attachedDeviceHandler) {
    this.attachedDeviceHandler = attachedDeviceHandler;
  }

  public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (Constants.ACTION_USB_PERMISSION.equals(action)) {
      UsbDevice device = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
      if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {
        if (device != null) {
          try {
            attachedDeviceHandler.connectUsb(device);
          }
          catch (UsbConnectionException e) {
            e.printStackTrace();
          }
        }
      }
      else {
        Log.d(Constants.TAG, "permission denied for device " + device);
      }
    }
    else {
      Toast.makeText(context, action, Toast.LENGTH_LONG).show();
    }
  }
}




Java Source Code List

de.grundid.weather.Beeper.java
de.grundid.weather.Constants.java
de.grundid.weather.MainActivity.java
de.grundid.weather.SensorHandler.java
de.grundid.weather.SerialDataHandler.java
de.grundid.weather.io.AttachedDeviceHandler.java
de.grundid.weather.io.ConnectedUsbDevice.java
de.grundid.weather.io.PermissionBroadcastReceiver.java
de.grundid.weather.io.SerialReceiverListener.java
de.grundid.weather.io.SerialReceiver.java
de.grundid.weather.io.UsbConnectionException.java
de.grundid.weather.sensor.InsideSensor.java
de.grundid.weather.sensor.LightSensor.java
de.grundid.weather.sensor.OutsideSensor.java
de.grundid.weather.sensor.SensorFactory.java
de.grundid.weather.sensor.SensorListener.java
de.grundid.weather.sensor.Sensor.java
de.grundid.weather.sensor.WeatherLogger.java
de.grundid.weather.utils.Utils.java