I would like to enable/disable Wifi and Hotspot using NativeScript Angular But I could find any way for that, Give some idea to enable/disable Wifi and Hotspot.
You can check the docs, here, they have an example on how to work with connections:
import { connectionType, getConnectionType, startMonitoring, stopMonitoring }from "tns-core-modules/connectivity";
export function onNavigatedTo(args) {
const page = args.object;
let connectionTypeString;
const type = getConnectionType();
switch (type) {
case connectionType.none:
console.log("No connection");
connectionTypeString = "No Internet connectivity!";
break;
case connectionType.wifi:
console.log("WiFi connection");
connectionTypeString = "WiFI connectivity!";
break;
case connectionType.mobile:
console.log("Mobile connection");
connectionTypeString = "Mobile connectivity!";
break;
case connectionType.ethernet:
console.log("Ethernet connection");
connectionTypeString = "Ethernet connectivity!";
break;
case connectionType.bluetooth:
console.log("Bluetooth connection");
connectionTypeString = "Bluetooth connectivity!";
break;
default:
break;
}
startMonitoring((newConnectionType) => {
switch (newConnectionType) {
case connectionType.none:
console.log("Connection type changed to none.");
break;
case connectionType.wifi:
console.log("Connection type changed to WiFi.");
break;
case connectionType.mobile:
console.log("Connection type changed to mobile.");
break;
case connectionType.ethernet:
console.log("Connection type changed to ethernet.");
break;
case connectionType.bluetooth:
console.log("Connection type changed to bluetooth.");
break;
default:
break;
}
});
// Stoping the connection monitoring
stopMonitoring();
page.bindingContext = { connectionType: connectionTypeString };
}
Now hotspot is a different issue, as far as I know there is no core module to handle this, so i recommend to access the native implementation and try hard.
Check this out this question.
Related
I am trying to create an UDP application where the packet generation rate and packet send interval can be controlled separately.
My code is in https://github.com/11187162/udpApp
With the above code, I am not getting the expected outcome and getting the following runtime error:
scheduleAt(): Message (omnetpp::cMessage)sendTimer is currently
scheduled, use cancelEvent() before rescheduling -- in module
(inet::UdpOwnApp) SensorNetworkShowcaseA.sensor3.app[0] (id=176), at
t=0.058384669093s, event #10
The code for handleMessageWhenUp() is given below.
void UdpOwnApp::handleMessageWhenUp(cMessage *msg)
{
if (msg->isSelfMessage()) {
ASSERT(msg == selfMsg);
switch (selfMsg->getKind()) {
case START:
processStart();
break;
case GENERATE:
generatePacket();
break;
case SEND:
processSend();
break;
case STOP:
processStop();
break;
default:
throw cRuntimeError("Invalid kind %d in self message", (int)selfMsg->getKind());
}
}
else
socket.processMessage(msg);
}
Would anyone please help me?
Thank you
You have written that "generation rate and packet send interval can be controlled separately" but you use the same self-message for control generation of packets as well as for sending of the packets. When a self-message is scheduled it cannot be scheduled again.
Consider adding a new self-message for generation of packets.
By the way: numGenerate is set to zero and it is never changed.
EDIT
Assuming that selfMsg1 is used for generating packets only the following code may be used:
void UdpOwnApp::handleMessageWhenUp(cMessage *msg) {
if (msg->isSelfMessage()) {
if (msg == selfMsg) {
switch (selfMsg->getKind()) {
case START:
processStart();
break;
case SEND:
processSend();
break;
case STOP:
processStop();
break;
default:
throw cRuntimeError("Invalid kind %d in self message", (int)selfMsg->getKind());
}
} else if (msg == selfMsg1) {
if (selfMsg1->getKind() == GENERATE) {
generatePacket();
}
}
}
else
socket.processMessage(msg);
}
And in initialize() you should create an instance of selfMsg1.
Looking at this code, I'm wondering what triggers onNotificationGCM? It is triggered when the app is registered but when does it get triggered again, say, when when I want to push a message to the user? I have a chat app that I'd like to push a message when chats come in. So I understand that I register the device but then this code needs to run again, I assume, with the new event. I just need understand part flow and part code.
// handle GCM notifications for Android
$window.onNotificationGCM = function (event) {
switch (event.event) {
case 'registered':
if (event.regid.length > 0) {
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
var device_token = event.regid;
RequestsService.register(device_token).then(function(response){
alert('registered!');
});
//send device reg id to server
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (event.foreground) {
console.log('INLINE NOTIFICATION');
var my_media = new Media("/android_asset/www/" + event.soundname);
my_media.play();
} else {
if (event.coldstart) {
console.log('COLDSTART NOTIFICATION');
} else {
console.log('BACKGROUND NOTIFICATION');
}
}
navigator.notification.alert(event.payload.message);
console.log('MESSAGE -> MSG: ' + event.payload.message);
//Only works for GCM
console.log('MESSAGE -> MSGCNT: ' + event.payload.msgcnt);
//Only works on Amazon Fire OS
console.log('MESSAGE -> TIME: ' + event.payload.timeStamp);
break;
case 'error':
console.log('ERROR -> MSG:' + event.msg);
break;
default:
console.log('EVENT -> Unknown, an event was received and we do not know what it is');
break;
}
};
Have a look at this example:
case 'message':
/*
if (e.foreground) {
window.alert("Message recieved");
}
else {
if (e.coldstart) {
window.alert("Coldstart Notification");
} else {
window.alert("Background Notification");
}
}
window.alert("Notification message: " + e.payload.message
+ "\n\n Time: " + e.payload.conversation);
*/
var data = e.payload;
if (data.conversation){
window.history.replaceState(null, '', '#/chats/');
ProjectName.conversation.load(data.conversation);
}
if (data.product){
window.history.replaceState(null, '', '#/product/' + data.product);
}
break;
case 'error':
// window.alert("Notification error: " + e.msg);
break;
default:
// window.alert("Notification - Unknown event");
break;
}
The e.payload contains all data that you send to your application, including message. You can access your other variables in case 'message'
I have used below function for check network status in windows mobile simulator. It returns "unknown" either ethertnet present or not.
function checkConnection() {
var networkState = navigator.network.connection.type;
var states = {};
states[Connection.UNKNOWN] = 'Unknown connection';
states[Connection.ETHERNET] = 'Ethernet connection';
states[Connection.WIFI] = 'WiFi connection';
states[Connection.CELL_2G] = 'Cell 2G connection';
states[Connection.CELL_3G] = 'Cell 3G connection';
states[Connection.CELL_4G] = 'Cell 4G connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
checkConnection();
On Windows Phone, For get The current interface you can use the class 'NetworkInterfaceList' :
NetworkInterfaceInfo CurrentInterface;
var interfacesList = new NetworkInterfaceList();
foreach (NetworkInterfaceInfo specificInterface in interfacesList)
{
CurrentInterface = specificInterface;
break;
}
You can Subscribe to an event for the network changement :
DeviceNetworkInformation.NetworkAvailabilityChanged += NetworkChanged;
private void NetworkChanged(object sender, NetworkNotificationEventArgs e)
{
CurrentInterface = e.NetworkInterface;
}
After get the current interface, you can get the true type of network :
switch (CurrentInterface.InterfaceType)
{
case NetworkInterfaceType.Ethernet:
// ETHERNET (USB connected)
break;
case NetworkInterfaceType.MobileBroadbandCdma:
switch (pNetworkInterfaceInfo.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_GPRS:
// 2G
break;
case NetworkInterfaceSubType.Cellular_EDGE:
// 2GP
break;
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
// ?
break;
case NetworkInterfaceSubType.Cellular_1XRTT:
// ?
break;
case NetworkInterfaceSubType.Cellular_3G:
// 3G
break;
case NetworkInterfaceSubType.Cellular_HSPA:
// 3GP
break;
case NetworkInterfaceSubType.Unknown:
// Unknonwn ? 4G is Unknown.
break;
}
break;
case NetworkInterfaceType.MobileBroadbandGsm:
switch (pNetworkInterfaceInfo.InterfaceSubtype)
{
case NetworkInterfaceSubType.Cellular_GPRS:
// 2G
break;
case NetworkInterfaceSubType.Cellular_EDGE:
// 2GP
break;
case NetworkInterfaceSubType.Cellular_EVDO:
case NetworkInterfaceSubType.Cellular_EVDV:
// ??
break;
case NetworkInterfaceSubType.Cellular_1XRTT:
// ??
break;
case NetworkInterfaceSubType.Cellular_3G:
// 3G
break;
case NetworkInterfaceSubType.Cellular_HSPA:
// 3GP
break;
case NetworkInterfaceSubType.Unknown:
// Unknown? 4G is Unknown
break;
}
break;
case NetworkInterfaceType.Wireless80211:
// WIFI
break;
}
Note that with a Windows Phone 7 project, We haven't a "4G type", When I test the 4G with a device, The NetworkInterfaceType is unknown... but, if we have a network problems in 32G or 3G, is Unknown too..
I've not test with a Windows Phone 8 project, but, in theory, that works in 4G.
Also, you can have more details on the Networks type here.
PS: For test the network, there is nothing better than testing with a real device, and therefore, a real network.
I want at least to distinguish cases when my software is being ran as batch job (LOGON32_LOGON_BATCH) from being ran interactively (LOGON32_LOGON_INTERACTIVE).
HANDLE hToken;
// Open the current process's token
if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
{
// Get the token statistics, which include the logon session id
TOKEN_STATISTICS stats;
DWORD length;
if (GetTokenInformation(hToken, TokenStatistics, &stats, sizeof(stats), &length))
{
// Get data about the logon session, which includes the logon type
PSECURITY_LOGON_SESSION_DATA pData;
if (LsaGetLogonSessionData(&stats.AuthenticationId, &pData) == 0)
{
// From SECURITY_LOGON_TYPE enumeration
switch (pData->LogonType)
{
case Interactive:
wprintf(L"Interactive\n");
break;
case Batch:
wprintf(L"Batch\n");
break;
default:
wprintf(L"Other: %i\n", pData->LogonType);
break;
}
LsaFreeReturnBuffer(pData);
}
}
CloseHandle(hToken);
}
Declare a GeoCoordinateWatcher tracker. This tracker will start on PageOnload event as below.
I dont know how to create a condition such that it will show this :case GeoPositionStatus.NoData, So I need some advise. My objective is it will re-start until it gets the current Latitude and longitude.
Q1) for case GeoPositionStatus.NoData, what will be the best practice to re-start the GeoCoordinateWatcher?
Do this in case GeoPositionStatus.NoData
tracker.Stop();
tracker.Start();
void tracker_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Disabled:
if (tracker.Permission == GeoPositionPermission.Denied)
{
MessageBox.Show("The location Service on this device is off.Please read privacy.");
}
else
{
MessageBox.Show("Location service is working but it can not get location data.");
}
break;
case GeoPositionStatus.Initializing:
// Code which needs to be initialized goes here
break;
case GeoPositionStatus.NoData:
//MessageBox.Show("Location data is not available.");
break;
case GeoPositionStatus.Ready:
// Code which needs to be executed when location data is available goes here
break;
}
}