()
| 42 | * @returns current application instance, UIApplication on iOS or android.app.Application on Android. |
| 43 | */ |
| 44 | export function getNativeApp<T extends NativeApp>(): T { |
| 45 | if (__ANDROID__) { |
| 46 | if (!nativeApp) { |
| 47 | // Try getting it from module - check whether application.android.init has been explicitly called |
| 48 | // check whether the com.tns.NativeScriptApplication type exists |
| 49 | if (com.tns.NativeScriptApplication) { |
| 50 | nativeApp = com.tns.NativeScriptApplication.getInstance(); |
| 51 | } |
| 52 | |
| 53 | if (!nativeApp && isEmbedded()) { |
| 54 | nativeApp = com.tns.embedding.ApplicationHolder.getInstance(); |
| 55 | } |
| 56 | |
| 57 | // the getInstance might return null if com.tns.NativeScriptApplication exists but is not the starting app type |
| 58 | if (!nativeApp) { |
| 59 | // TODO: Should we handle the case when a custom application type is provided and the user has not explicitly initialized the application module? |
| 60 | const clazz = java.lang.Class.forName('android.app.ActivityThread'); |
| 61 | if (clazz) { |
| 62 | const method = clazz.getMethod('currentApplication', null); |
| 63 | if (method) { |
| 64 | nativeApp = method.invoke(null, null); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | return nativeApp! as T; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * This is called internally to set the native application instance. |
no test coverage detected