FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix: connectivity module always returns undefined on android <= 4.4 by hamorphis · Pull Request #3105 · NativeScript/NativeScript · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ts  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
27 changes: 15 additions & 12 deletions tns-core-modules/connectivity/connectivity.android.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import utils = require("utils/utils");

global.moduleMerge(common, exports);

var WIFI = "WIFI";
var MOBILE = "MOBILE";
let wifi = "wifi";
let mobile = "mobile";

// Get Connection Type
function getConnectivityManager(): android.net.ConnectivityManager {
return utils.ad.getApplicationContext().getSystemService(android.content.Context.CONNECTIVITY_SERVICE);
}

function getActiveNetworkInfo(): android.net.NetworkInfo {
var connectivityManager = getConnectivityManager();
let connectivityManager = getConnectivityManager();
if (!connectivityManager) {
return null;
}
Expand All @@ -22,23 +22,26 @@ function getActiveNetworkInfo(): android.net.NetworkInfo {
}

export function getConnectionType(): number {
var activeNetworkInfo = getActiveNetworkInfo();
let activeNetworkInfo = getActiveNetworkInfo();
if (!activeNetworkInfo || !activeNetworkInfo.isConnected()) {
return common.connectionType.none;
}

var connectionType = activeNetworkInfo.getTypeName();
switch (connectionType) {
case WIFI:
return common.connectionType.wifi;
case MOBILE:
return common.connectionType.mobile;
let connectionType = activeNetworkInfo.getTypeName().toLowerCase();
if (connectionType.indexOf(wifi) !== -1){
return common.connectionType.wifi;
}

if (connectionType.indexOf(mobile) !== -1){
return common.connectionType.mobile;
}

return common.connectionType.none;
}

export function startMonitoring(connectionTypeChangedCallback: (newConnectionType: number) => void): void {
var onReceiveCallback = function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) {
var newConnectionType = getConnectionType();
let onReceiveCallback = function onReceiveCallback(context: android.content.Context, intent: android.content.Intent) {
let newConnectionType = getConnectionType();
connectionTypeChangedCallback(newConnectionType);
}
appModule.android.registerBroadcastReceiver(android.net.ConnectivityManager.CONNECTIVITY_ACTION, onReceiveCallback);
Expand Down

Back | FazBrowse Home | New Git URL