FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
NativeScript/apps/tests/application-tests.android.ts at patch-1 · rclai/NativeScript · GitHub
rclai
NativeScript
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
NativeScript
/
apps
/
tests
/
application-tests.android.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (55 loc) · 2.39 KB
Breadcrumbs
NativeScript
/
apps
/
tests
/
application-tests.android.ts
Copy path
File metadata and controls
58 lines (55 loc) · 2.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* tslint:disable:no-unused-variable */
import
app
=
require
(
"application"
)
;
import
TKUnit
=
require
(
"./TKUnit"
)
;
import
commonTests
=
require
(
"./application-tests-common"
)
;
global
.
moduleMerge
(
commonTests
,
exports
)
;
// <snippet module="application" title="application">
// ### Using the Android-specific implementation
// Accessing the Android-specific object instance (will be undefined if running on iOS)
// ``` JavaScript
var
androidApp
=
app
.
android
;
// ```
// </snippet>
// <snippet module="application" title="application">
// ### Using the Android Application context
// ``` JavaScript
var
context
=
app
.
android
.
context
;
//// get the Files (Documents) folder (directory)
var
dir
=
context
.
getFilesDir
(
)
;
// ```
// </snippet>
// <snippet module="application" title="application">
// ### Tracking the current Activity
// ``` JavaScript
if
(
androidApp
.
foregroundActivity
===
androidApp
.
startActivity
)
{
////console.log("We are currently in the main (start) activity of the application");
}
// ```
// </snippet>
// <snippet module="application" title="application">
// ### Registering a Broadcast Receiver (Android)
// ``` JavaScript
//// Register the broadcast receiver
if
(
app
.
android
)
{
app
.
android
.
registerBroadcastReceiver
(
android
.
content
.
Intent
.
ACTION_BATTERY_CHANGED
,
function
onReceiveCallback
(
context
:
android
.
content
.
Context
,
intent
:
android
.
content
.
Intent
)
{
var
level
=
intent
.
getIntExtra
(
android
.
os
.
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
;
var
scale
=
intent
.
getIntExtra
(
android
.
os
.
BatteryManager
.
EXTRA_SCALE
,
-
1
)
;
var
percent
=
(
level
/
scale
)
*
100.0
;
////console.log("Battery: " + percent + "%");
}
)
;
}
//// When no longer needed, unregister the broadcast receiver
if
(
app
.
android
)
{
app
.
android
.
unregisterBroadcastReceiver
(
android
.
content
.
Intent
.
ACTION_BATTERY_CHANGED
)
;
}
// ```
// </snippet>
export
var
testAndroidApplicationInitialized
=
function
(
)
{
TKUnit
.
assert
(
app
.
android
,
"Android application not initialized."
)
;
TKUnit
.
assert
(
app
.
android
.
context
,
"Android context not initialized."
)
;
TKUnit
.
assert
(
app
.
android
.
foregroundActivity
,
"Android currentActivity not initialized."
)
;
TKUnit
.
assert
(
app
.
android
.
startActivity
,
"Android startActivity not initialized."
)
;
TKUnit
.
assert
(
app
.
android
.
nativeApp
,
"Android nativeApp not initialized."
)
;
TKUnit
.
assert
(
app
.
android
.
packageName
,
"Android packageName not initialized."
)
;
}
Back
|
FazBrowse Home
|
New Git URL