Foro de elhacker.net

Programación => Java => Mensaje iniciado por: kondrag_X1 en 27 Julio 2015, 11:58 am



Título: [Android] Por qué funciona y salta excepcion del error.
Publicado por: kondrag_X1 en 27 Julio 2015, 11:58 am
Hola,
les comento gente estoy haciendo un controlador BLE (Bluetooth low energy). Estoy montando una arquitectura separando el controlador BLE de la GUI y demás pero tengo un error que aunque el programa funciona me gustaría corregirlo.

Os explico:
Tengo una clase para manejar los dispositivos BLE:
Código
  1. package pfc.teleco.upct.es.iot_ble.BLE;
  2.  
  3. import android.bluetooth.BluetoothAdapter;
  4. import android.bluetooth.BluetoothAdapter.LeScanCallback;
  5. import android.bluetooth.BluetoothDevice;
  6. import android.bluetooth.BluetoothGatt;
  7. import android.bluetooth.BluetoothGattCallback;
  8. import android.bluetooth.BluetoothGattCharacteristic;
  9. import android.bluetooth.BluetoothGattDescriptor;
  10. import android.bluetooth.BluetoothGattService;
  11. import android.bluetooth.BluetoothManager;
  12. import android.bluetooth.BluetoothProfile;
  13. import android.content.Context;
  14. import android.content.Intent;
  15. import android.util.Log;
  16.  
  17. import java.util.ArrayList;
  18. import java.util.List;
  19. import java.util.UUID;
  20.  
  21. import pfc.teleco.upct.es.iot_ble.BEAN.BeanBluetoothDevice;
  22. import pfc.teleco.upct.es.iot_ble.Constant;
  23. import pfc.teleco.upct.es.iot_ble.DEVICES.Device;
  24.  
  25. public class HandlerBLE implements LeScanCallback
  26. {
  27.    public static final String ACTION_DEVICE_CONNECTED = "pfc.teleco.upct.es.iot_ble.DEVICE_FOUND";
  28.  
  29.    private static HandlerBLE mHandlerBLE;
  30.    private static Context mContext;
  31.    private static BluetoothDevice mDevice;
  32.    private static String mDeviceAddress;
  33.    private static BluetoothGatt mGatt;
  34.    private static BluetoothAdapter mBlueAdapter = null;
  35.  
  36.    public static boolean isScanning = false;
  37.  
  38.    //###################################################################
  39.    /****************** Constructor                **********************/
  40.    //###################################################################
  41.    public HandlerBLE(Context context)
  42.    {
  43.        mContext = context;
  44.        mDeviceAddress= null;
  45.    }
  46.  
  47.    //###################################################################
  48.    /*********************  statics methods   **************************/
  49.    //###################################################################
  50.    public static HandlerBLE getInstance(Context context) {
  51.        if(mHandlerBLE==null){
  52.            mHandlerBLE = new HandlerBLE(context);
  53.            setup();
  54.        }
  55.        return mHandlerBLE;
  56.    }
  57.  
  58.    public static void  resetHandlerBLE()
  59.    {
  60.        mDeviceAddress=null;
  61.        disconnect();
  62.        mGatt=null;
  63.    }
  64.  
  65.    public static void setup()
  66.    {
  67.        BluetoothManager manager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
  68.        mBlueAdapter = manager.getAdapter();
  69.    }
  70.  
  71.    //###################################################################
  72.    /********************* methods bluetooth                *************/
  73.    //###################################################################
  74.  
  75.    public void setDeviceAddress(String address) {
  76.        mDeviceAddress=address;
  77.    }
  78.  
  79.    public String getDeviceAddress() {
  80.        return mDeviceAddress;
  81.    }
  82.  
  83.    public void startLeScan()
  84.    {
  85.        try
  86.        {
  87.            mBlueAdapter.startLeScan(this);//deprecated
  88.            isScanning = true;
  89.            //mBlueAdapter.startDiscovery();
  90.        }
  91.        catch (Exception e)
  92.        {
  93.            Log.i(Constant.TAG,"(HandlerBLE)[Error]:"+e.getStackTrace()+" "+e.getCause()+" "+e.getMessage()+
  94.                    " "+e.getLocalizedMessage());
  95.        }
  96.  
  97.    }
  98.  
  99.    public void stopLeScan()
  100.    {
  101.        try
  102.        {
  103.            mBlueAdapter.stopLeScan(this); //deprecated
  104.            //mBlueAdapter.startDiscovery();
  105.            isScanning = false;
  106.        }
  107.        catch(Exception e)
  108.        {
  109.            Log.i(Constant.TAG,"(HandlerBLE)[Error]:"+e.getStackTrace()+" "+e.getCause()+" "+e.getMessage()+
  110.                    " "+e.getLocalizedMessage());
  111.        }
  112.    }
  113. /*
  114.     public void connect() {
  115.         mDevice   = mBlueAdapter.getRemoteDevice(mDeviceAddress);
  116.         mServices.clear();
  117.         if(mGatt!=null){
  118.             mGatt.connect();
  119.         }else{
  120.             mDevice.connectGatt(mContext, false, mCallBack);
  121.         }
  122.     }
  123. */
  124.    public void discoverServices() {
  125.        if (Constant.DEBUG)
  126.            Log.i(Constant.TAG, "(HandlerBLE)Scanning services and caracteristics");
  127.        mGatt.discoverServices();
  128.    }
  129.  
  130.    public static void disconnect(){
  131.        if (mGatt!=null) {
  132.            try{
  133.                mGatt.disconnect();
  134.                mGatt.close();
  135.                if (Constant.DEBUG)
  136.                    Log.i(Constant.TAG, "(HandlerBLE)Disconnecting GATT");
  137.            } catch(Exception ex){};
  138.        }
  139.        mGatt = null;
  140.    }
  141.  
  142.    public boolean isConnected(){
  143.        return (mGatt!=null);
  144.    }
  145.  
  146.    //###################################################################
  147.    /********************* methods Scan bluetooth          *************/
  148.    //###################################################################
  149.    /*
  150.     * this method is used to receive devices which were found durind a scan*/
  151.    @Override
  152.    public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
  153.    {
  154.        if(Constant.DEBUG)
  155.            Log.i(Constant.TAG,"(HandlerBLE) -- onLeScan -> throwing information to the listener.");
  156.  
  157.        //create the packet wich will be sent to listener.
  158.        Intent intent = new Intent();
  159.        intent.setAction(HandlerBLE.ACTION_DEVICE_CONNECTED);
  160.  
  161.        BeanBluetoothDevice beanBlue = new BeanBluetoothDevice();
  162.        beanBlue.setBluetoothDevice(device);
  163.        beanBlue.setmRssi(rssi);
  164.        beanBlue.setmScanRecord(scanRecord);
  165.  
  166.        intent.putExtra(Constant.EXTRA_BEAN_BLUETOOTHDEVICE,beanBlue);
  167.        mContext.sendBroadcast(intent);
  168.    }
  169. }
  170.  

Esta clase se encargará de controlar el BLE sanea, conexión y comunicación con otros dispositivos. Y a su vez se comunicará con el resto de la aplicación con Broadcastreceiver , es decir en el método implementado en la interfaz onLeScan, me avisa cuando se ha encontrado un dispositivo y envia la señal broadcast.

Como se puede ver tengo un objeto llamado BeanBluetoothDevice este simplemente es una encapsulación de la información que necesito y serializado.

Código
  1. public class BeanBluetoothDevice implements Parcelable
  2. {
  3.    private BluetoothDevice mdevice;
  4.    private int mRssi;
  5.    private byte[] mScanRecord;
  6.  
  7.    public BeanBluetoothDevice() {
  8.        super();
  9.    }
  10.  
  11.    //###################################################################
  12.  
  13.    protected BeanBluetoothDevice(Parcel in) {
  14.        mdevice     = in.readParcelable(BluetoothDevice.class.getClassLoader());
  15.        mRssi       = in.readInt();
  16.        mScanRecord = in.createByteArray();
  17.    }
  18.  
  19.    public static final Creator<BeanBluetoothDevice> CREATOR = new Creator<BeanBluetoothDevice>() {
  20.        @Override
  21.        public BeanBluetoothDevice createFromParcel(Parcel in) {
  22.            return new BeanBluetoothDevice(in);
  23.        }
  24.  
  25.        @Override
  26.        public BeanBluetoothDevice[] newArray(int size) {
  27.            return new BeanBluetoothDevice[size];
  28.        }
  29.    };
  30.  
  31.    //###################################################################
  32.    /****************** gets and sets methods     **********************/
  33.    //###################################################################
  34.  
  35.    public void setBluetoothDevice(BluetoothDevice device)
  36.    {mdevice = device;}
  37.  
  38.    public BluetoothDevice getBluetoothDevice()
  39.    {return mdevice;}
  40.  
  41.    public int getmRssi() {
  42.        return mRssi;
  43.    }
  44.  
  45.    public void setmRssi(int mRssi) {
  46.        this.mRssi = mRssi;
  47.    }
  48.  
  49.    public byte[] getmScanRecord() {
  50.        return mScanRecord;
  51.    }
  52.  
  53.    public void setmScanRecord(byte[] mScanRecord) {
  54.        this.mScanRecord = mScanRecord;
  55.    }
  56.  
  57.  
  58.    @Override
  59.    public int describeContents() {
  60.        return 0;
  61.    }
  62.  
  63.    @Override
  64.    public void writeToParcel(Parcel dest, int flags) {
  65.        dest.writeParcelable(mdevice, flags);
  66.        dest.writeInt(mRssi);
  67.        dest.writeByteArray(mScanRecord);
  68.    }
  69. }
  70.  


una vez e envia la señal yo la recojo en la activity que me interesa, en mi casa es la principal para mostrar los dispositivos.
Código
  1. public class ScanActivity extends ListActivity implements OnItemClickListener{ //}, LeScanCallback {
  2.  
  3.    private static final int SCAN_ITEM = 1;
  4.    private static ListView mListView;
  5.    private static Context mContext;
  6.    private static HandlerBLE mHandlerBLE;
  7.    private Handler mHandler;
  8.    private static MySimpleArrayAdapter mAdapter;
  9.    private static List<BluetoothDevice> mDeviceList;
  10.    private Menu mMenu;
  11.    private Activity mActivity;
  12.    private BLEBroadcastReceiver mScanBroadcastReceiver;
  13.  
  14.  
  15.    //###################################################################
  16.    /****************** metodos del flujo Android. **********************/
  17.    //###################################################################
  18.    @Override
  19.    protected void onCreate(Bundle savedInstanceState) {
  20.        super.onCreate(savedInstanceState);
  21.        setContentView(R.layout.activity_scan);
  22.  
  23.        mActivity   = this;
  24.        mContext    = this;
  25.        mHandler    = new Handler() ;
  26.        mDeviceList = new ArrayList<BluetoothDevice>();
  27.        mAdapter    = new MySimpleArrayAdapter(mContext, mDeviceList);
  28.        mScanBroadcastReceiver = new BLEBroadcastReceiver(this,mAdapter);
  29.  
  30.        IntentFilter i = new IntentFilter(HandlerBLE.ACTION_DEVICE_CONNECTED);
  31.        registerReceiver(mScanBroadcastReceiver,i);
  32.  
  33.        if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
  34.            Toast.makeText(this, "BLE TECHNOLOGY NOT SUPPORTED ON THIS DEVICE", Toast.LENGTH_SHORT).show();
  35.            finish();
  36.        }
  37.  
  38.  
  39.  
  40.  
  41.        //run service
  42.        Intent service = new Intent(this, ServiceDetectionTag.class);
  43.        startService(service);
  44.  
  45.        //manejador BLE
  46.        mHandlerBLE = ((BLE_Application) getApplication()).getmHandlerBLEInstance(this);
  47.        ((BLE_Application) getApplication()).resetHandlerBLE();
  48.  
  49.        mListView = getListView();
  50.        mListView.setVisibility(View.VISIBLE);
  51.  
  52.        mListView.setAdapter(mAdapter);
  53.        mListView.setOnItemClickListener(this);
  54.  
  55.    }
  56.  
  57.    @Override
  58.    public boolean onCreateOptionsMenu(Menu menu)
  59.    {
  60.        super.onCreateOptionsMenu(menu);
  61.        mMenu = menu;
  62.        String menuTitle= getResources().getString(R.string.scan);
  63.        menu.add(0,SCAN_ITEM,0,menuTitle);
  64.  
  65.       /*
  66.         // Inflate the menu; this adds items to the action bar if it is present.
  67.         getMenuInflater().inflate(R.menu.menu_scan, menu);*/
  68.        return true;
  69.    }
  70.  
  71.    @Override
  72.    public boolean onOptionsItemSelected(MenuItem item)
  73.    {
  74.        switch (item.getItemId()){
  75.            case SCAN_ITEM:
  76.                scan();
  77.                break;
  78.        }
  79.        return true;
  80.        /*
  81.         // Handle action bar item clicks here. The action bar will
  82.         // automatically handle clicks on the Home/Up button, so long
  83.         // as you specify a parent activity in AndroidManifest.xml.
  84.         int id = item.getItemId();
  85.  
  86.         //noinspection SimplifiableIfStatement
  87.         if (id == R.id.action_settings) {
  88.             return true;
  89.         }
  90.  
  91.         return super.onOptionsItemSelected(item);*/
  92.    }
  93.  
  94.  
  95.    @Override
  96.    protected void onResume()
  97.    {
  98.        super.onResume();
  99.        //mAdapter.clear();
  100.        HandlerBLE.setup();
  101.    }
  102.  
  103.    @Override
  104.    protected void onPause() {
  105.        super.onStop();
  106.        //Make sure that there is no pending Callback
  107.        mHandler.removeCallbacks(mStopRunnable);
  108.  
  109.        //stop service
  110.        Intent service = new Intent(this, ServiceDetectionTag.class);
  111.        stopService(service);
  112.  
  113.        //mAdapter.clear();
  114.  
  115.        if (mHandlerBLE.isScanning)
  116.        {
  117.            mHandlerBLE.stopLeScan();
  118.            unregisterReceiver(mScanBroadcastReceiver);
  119.        }
  120.    }
  121.  
  122.    @Override
  123.    protected void onStop()
  124.    {
  125.        super.onStop();
  126.    }
  127.  
  128.    //###################################################################
  129.    /****************** metodos manejo Tag        **********************/
  130.    //###################################################################
  131.    @Override
  132.    //recogemos los metodos del tag seleccionado y recogemos los datos.
  133.    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
  134.    {
  135.        if (Constant.DEBUG)
  136.            Log.i(Constant.TAG, "Selected device " + mDeviceList.get(position).getAddress());
  137.  
  138.        if (mHandlerBLE.isScanning)
  139.        { //stop scanning
  140.            configureScan(false);
  141.            mHandlerBLE.stopLeScan();
  142.            if (Constant.DEBUG)
  143.                Log.i(Constant.TAG, "Stop scanning");
  144.        }
  145.  
  146.        String address  = mDeviceList.get(position).getAddress();
  147.        String name     = mDeviceList.get(position).getName();
  148.  
  149.        if (name==null)
  150.            name="unknown";
  151.  
  152.        Intent intentActivity= new Intent(this, DeviceActivity.class);
  153.        intentActivity.putExtra(Constant.EXTRA_ADDRESS, address);
  154.        intentActivity.putExtra(Constant.EXTRA_NAME, name);
  155.        this.startActivity(intentActivity);
  156.  
  157.        if (Constant.DEBUG)
  158.            Log.i(Constant.TAG, "Trying to connect");
  159.        //mConnectionManager.connect(address,true);
  160.        Toast.makeText(this, "Wait for connection to selected device", Toast.LENGTH_LONG).show();
  161.    }
  162.  
  163.    //Handle automatic stop of LEScan
  164.    private Runnable mStopRunnable = new Runnable() {
  165.        @Override
  166.        public void run() {
  167.            mHandlerBLE.stopLeScan();
  168.            configureScan(false);
  169.            if (Constant.DEBUG)
  170.                Log.i(Constant.TAG, "Stop scanning");
  171.        }
  172.    };
  173.  
  174.    public void configureScan(boolean flag)
  175.    {
  176.        //isScanning      = flag;
  177.        String itemText = null;
  178.  
  179.        if (mHandlerBLE.isScanning)
  180.        {
  181.            itemText = getResources().getString(R.string.stopScan);
  182.            mHandlerBLE.stopLeScan();
  183.            if (Constant.DEBUG)
  184.                Log.i(Constant.TAG, "ScanActivity -- StopScan");
  185.        }
  186.        else
  187.        {
  188.            itemText= getResources().getString(R.string.scan);
  189.            mHandlerBLE.startLeScan();
  190.  
  191.            if (Constant.DEBUG)
  192.                Log.i(Constant.TAG, "ScanActivity -- StartScan");
  193.        }
  194.  
  195.        mMenu.findItem(SCAN_ITEM).setTitle(itemText);
  196.  
  197.        if (Constant.DEBUG)
  198.            Log.i(Constant.TAG, "Updated Menu Item. New value: " + itemText);
  199.    }
  200.  
  201.    // Metodo para iniciar el scaneo cuando te llaman manualmente.
  202.    private void scan() {
  203.        if (mHandlerBLE.isScanning) { //stop scanning
  204.            configureScan(false);
  205.            mHandlerBLE.stopLeScan();
  206.  
  207.            if (Constant.DEBUG)
  208.                Log.i(Constant.TAG, "Stop scanning");
  209.  
  210.            return;
  211.        } else {
  212.            mAdapter.clear();
  213.            mAdapter.notifyDataSetChanged();
  214.            configureScan(true);
  215.  
  216.            if (Constant.DEBUG)
  217.                Log.i(Constant.TAG, "Start scanning for BLE devices...");
  218.  
  219.            mHandlerBLE.startLeScan();
  220.            //automatically stop LE scan after 5 seconds
  221.            mHandler.postDelayed(mStopRunnable, 30000);
  222.        }
  223.    }
  224.  
  225.  
  226.    /*
  227.     Clase para crear el adaptador de dispositos Bluetooh
  228.      */
  229.    public class MySimpleArrayAdapter extends ArrayAdapter<BluetoothDevice> {
  230.        private final Context context;
  231.  
  232.        public MySimpleArrayAdapter(Context context, List<BluetoothDevice> deviceList)
  233.        {
  234.            super(context, R.layout.activity_scan_item,R.id.deviceName, deviceList);
  235.            this.context = context;
  236.        }
  237.    }
  238.  
  239.    /*
  240.     @Override
  241.     public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord)
  242.     {
  243.         String name="unknown";
  244.  
  245.         if (device.getName()!=null)
  246.             name=device.getName();
  247.  
  248.         final String finalName = name;
  249.         final String  finalAddress = device.getAddress();
  250.  
  251.         if (Constant.DEBUG)
  252.             Log.i(Constant.TAG, "Found new device "+ finalAddress + " --- Name: " + finalName);
  253.  
  254.         final BluetoothDevice finalDevice= device;
  255.         // This callback from Bluetooth LEScan can arrive at any moment not necessarily on UI thread.
  256.         // Use this mechanism to update list View
  257.         mActivity.runOnUiThread(new Runnable() {
  258.                                     @Override
  259.                                     public void run() {
  260.                                         mAdapter.add(finalDevice);
  261.                                         mAdapter.notifyDataSetChanged();
  262.  
  263.                                         if (Constant.DEBUG)
  264.                                             Log.i(Constant.TAG, "Added new device "+ finalAddress + " --- Name: " + finalName);
  265.                                     }
  266.                                 }
  267.         );
  268.     }*/
  269.  
  270. }
  271.  

Como se puede ver en el método onCreate doy de alta la señal que espero recibir.
Código
  1. mScanBroadcastReceiver = new BLEBroadcastReceiver(this,mAdapter);
  2.  
  3. IntentFilter i = new IntentFilter(HandlerBLE.ACTION_DEVICE_CONNECTED);
  4. registerReceiver(mScanBroadcastReceiver,i);
  5.  

Ahora nos dirigimos en la clase donde creo que está el problema, es la clase donde se recibe la señal Broadcast y se procesa.
Código
  1. public class BLEBroadcastReceiver extends BroadcastReceiver
  2. {
  3.    private Activity mActivity;
  4.    private ScanActivity.MySimpleArrayAdapter mAdapter;
  5.    public BLEBroadcastReceiver(Activity activity, ScanActivity.MySimpleArrayAdapter adapter)
  6.    {
  7.        super();
  8.        mAdapter  = adapter;
  9.        mActivity = activity;
  10.    }
  11.    public BLEBroadcastReceiver()
  12.    {
  13.        super();
  14.    }
  15.    @Override
  16.    public void onReceive(Context context, Intent intent)
  17.    {
  18.        if(Constant.DEBUG)
  19.            Log.i(Constant.TAG, "ScanActivity -- OnReceive() -> BroadcastReceiver new device found.");
  20.  
  21.        //get signal and add new device into MyarrayAdapter
  22.        if(intent.getAction().equals(HandlerBLE.ACTION_DEVICE_CONNECTED))
  23.        {
  24.            try
  25.            {
  26.                BeanBluetoothDevice beanDeviceFound = intent.getExtras().getParcelable(Constant.EXTRA_BEAN_BLUETOOTHDEVICE);
  27.                final BluetoothDevice deviceFound   = beanDeviceFound.getBluetoothDevice();
  28.  
  29.                mActivity.runOnUiThread(new Runnable() {
  30.                    @Override
  31.                    public void run() {
  32.                        mAdapter.add(deviceFound);
  33.                        mAdapter.notifyDataSetChanged();
  34.  
  35.                        if (Constant.DEBUG)
  36.                            Log.i(Constant.TAG, "Added new device " + deviceFound.getAddress() + " --- Name: " + deviceFound.getName());
  37.                    }
  38.                });
  39.            }catch(Exception e)
  40.            {
  41.                Log.i(Constant.TAG,"[Error(BLEBroadcastReceiver)]: "+e.getCause()+"\n"+e.getStackTrace()+"\n"+e.getLocalizedMessage());
  42.            }
  43.        }
  44.    }
  45. }
  46.  

aquí el problema me aparice cuando quito el constructor vacío, es decir, al que no se le pasan parámetros. Si lo eliminamos en tiempo de ejecución el programa peta y cuando se lo pongo todo corre normalmente, es decir, si me introduce el dispositivo en el arrayList pero a su vez me da una excepción de los objetos mAdapter y mActivity.

¿A qué puede deberse esto? Si al final lo introduce correctamente.

PD: soy un patata programando, no ser muy duros conmigo.


Título: Re: [Android] Por qué funciona y salta excepcion del error.
Publicado por: Usuario Invitado en 27 Julio 2015, 15:40 pm
Has dado demasiado info de cómo funciona, pero no de la excepción objeto de este tema. Pega el rastreo de pila para analizarlo. Otra cosa, ¿la clase que hereda de BroadcastReceiver es interna? Si es así, necesitas hacerla estática. Una clase interna es asociada a una instancia de la clase externa.


Título: Re: [Android] Por qué funciona y salta excepcion del error.
Publicado por: kondrag_X1 en 27 Julio 2015, 17:25 pm
Tienes toda la razón. Me explico mejor o trato de hacerlo.

El error, basicamente, es que me salta la excepción
Código
  1. catch(Exception e)
  2.            {
  3.                Log.i(Constant.TAG,"[Error(BLEBroadcastReceiver)]: "+e.getCause()+"\n"+e.getStackTrace()+"\n"+e.getLocalizedMessage());
  4.            }
  5.  

de la clase BLEBroadcastReceiver, la cual es publica y no pertenece al mismo paquete que la activity, la activity está en el paquete GUI.

El error parece debido a la clase Parcelable de la serialización pero no lo que entiendo es a que se debe el fallo.
 
Código:
07-27 17:18:26.156    8954-9111/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ ServiceDetectionTag Start scanning
07-27 17:18:41.156    8954-9111/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ ServiceDetectionTag Stop scanning
07-27 17:18:53.537    8954-8954/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ BLEBroadcastReceiver -- OnReceive() -> Added new device EC:4A:C2:B4:E3:B4 --- Name: I'm Flowmeter!!
07-27 17:18:56.156    8954-9111/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ ServiceDetectionTag Start scanning
07-27 17:18:57.287    8954-8971/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ (HandlerBLE) -- onLeScan -> throwing information to the listener.
07-27 17:19:07.781    8954-8954/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ BLEBroadcastReceiver -- OnReceive() -> BroadcastReceiver new device found.
07-27 17:19:09.139    8954-8954/pfc.teleco.upct.es.iot_ble I/IoT-APP﹕ [Error(BLEBroadcastReceiver)]:
    Message: null
    Cause:null
    StackTrace[Ljava.lang.StackTraceElement;@41d76bb0
    null

y este es el error que obtengo
Código:
    java.lang.SecurityException: need INSTALL_LOCATION_PROVIDER permission, or UID of a currently bound location provider
            at android.os.Parcel.readException(Parcel.java:1465)
            at android.os.Parcel.readException(Parcel.java:1419)
            at android.location.ILocationManager$Stub$Proxy.reportLocation(ILocationManager.java:1122)
            at com.android.location.provider.LocationProviderBase.reportLocation(LocationProviderBase.java:137)
            at com.google.android.location.network.NetworkLocationService.onHandleIntent(SourceFile:99)
            at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
            at android.os.Handler.dispatchMessage(Handler.java:110)
            at android.os.Looper.loop(Looper.java:193)
            at android.os.HandlerThread.run(HandlerThread.java:61)


Título: Re: [Android] Por qué funciona y salta excepcion del error.
Publicado por: Usuario Invitado en 27 Julio 2015, 18:03 pm
A mí me suena más a un bug con el tipo de dispositivo. Lo que no entiendo, es por qué cuando especificas un constructor vacío no sucede. De alguna manera, ese super() hace algo en el constructor de BroadcasterReceiver o el runtime instancia internamente a las subclases de BroadcasterReceiver y al no encontrar un constructor vacío, lanza excepción. Es raro, trata de reportarlo como bug a ver qué te dicen xD.


Título: Re: [Android] Por qué funciona y salta excepcion del error.
Publicado por: kondrag_X1 en 27 Julio 2015, 18:09 pm
ok muchísimas gracias. Yo pensaba que estaba haciendo un uso indebido del BroadcasterReceiver.