Returns true if the ClassLoader is for android.
(ClassLoader cl)
| 95 | * Returns true if the {@link ClassLoader} is for android. |
| 96 | */ |
| 97 | static boolean isAndroid(ClassLoader cl) { |
| 98 | try { |
| 99 | // Specify a class loader instead of null because we may be running under Robolectric |
| 100 | Class.forName("android.app.Application", /*initialize=*/ false, cl); |
| 101 | return true; |
| 102 | } catch (Exception e) { |
| 103 | // If Application isn't loaded, it might as well not be Android. |
| 104 | return false; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * For testing only: Loads service providers for the {@code klass} service using {@link |