mercredi 1 février 2017

Usage of reflection in Android a bad design?

I am new to Android development. I have one question regarding the usage of Reflection APIs from Android.

As for example I can write some code like this to connect Bluetooth

     try {
        Method connectMethod = proxy.getClass().getDeclaredMethod("connect", BluetoothDevice.class);
        if(!((Boolean) connectMethod.invoke(proxy, device))){
            Log.i(TAG, "Unable to start connection");
        } else {
            Log.i(TAG, "Connection Successful");
        }
    } catch (Exception e) {
        Log.e(TAG, "Unable to reflect android.bluetooth.BluetoothPan", e);
    }

Similarly other APIs can be used to set tethering and do other stuffs. These functions (like set tethering) are supposed to be done from the Setting application in phone by a user.

These are my questions ?

  1. Is it not recommended to use reflection in android development?
  2. If I create custom permissions for those functions and add to user permissions then is it supported by design ? Because there is no special permission (user permission) required for reflection API access.
  3. As per android design pattern is it a taboo to use reflection APIs ?




Aucun commentaire:

Enregistrer un commentaire