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.
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.
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.
Hide Lanscape mode in Android phone in NativeScript Angular
1.Allow both orientations in Android tablet
2.Restrict Landscape and allow only portriat version in phone
lockOrientation(orientation) {
const activity = app.android.startActivity;
switch (orientation) {
case 'unlocked':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
break;
case 'portrait-primary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
break;
case 'portrait-secondary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
break;
case 'landscape-primary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
break;
case 'landscape-secondary':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
break;
case 'portrait':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
break;
case 'landscape':
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
break;
default:
activity.setRequestedOrientation(android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
break;
}
just checking and calling the below method is working for me
if (app.android && device.deviceType === 'Phone') {
this.lockOrientation('portrait');
}
Use deviceType from platforms to know which device type the app is running. If it's Tablet then use nativescript orientation plugin to lock the orientation to portrait.
I am using the GeoCoordinateWatcher class to get the latitude and longitude of the windows phone 7, but when I debug this application on my windows phone,
I am getting GeoPositionStatus.NoData in my StatusChanged event. Please tell me what is wrong with the following code.
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
watcher.MovementThreshold = 10.0f;
// wire up event handlers
watcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_statusChanged);
watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
void watcher_statusChanged(object sender, GeoPositionStatusChangedEventArgs e)
{
switch (e.Status)
{
case GeoPositionStatus.Disabled:
if (watcher.Permission == GeoPositionPermission.Denied)
{
// the user has disabled LocServ on their device.
statusTextBlock.Text = "You have disabled Location Service.";
}
else
{
statusTextBlock.Text = "Location Service is not functioning on this device.";
}
break;
case GeoPositionStatus.Initializing:
// The location service is initializing.
statusTextBlock.Text = "Location Service is retrieving data...";
break;
case GeoPositionStatus.NoData:
// The Location Service is working, but it cannot get location data
// due to poor signal fidelity (most likely)
statusTextBlock.Text = "Location data is not available.";
break;
case GeoPositionStatus.Ready:
// The location service is working and is receiving location data.
statusTextBlock.Text = "Location data is available.";
break;
}
}
void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs <GeoCoordinate> e)
{
// update the textblock readouts.
latitudeTextblock.Text = e.Position.Location.Latitude.ToString("0.0000000000");
longitudeTextblock.Text = e.Position.Location.Longitude.ToString("0.0000000000");
speedreadout.Text = e.Position.Location.Speed.ToString("0.0") + " meters per second";
coursereadout.Text = e.Position.Location.Course.ToString("0.0") + " degrees";
altitudereadout.Text = e.Position.Location.Altitude.ToString("0.0") + " meters above sea level";
}
You should start the watcher.
watcher.Start(...);
I see that you've discovered that location services was turned off. But something to keep in mind is in certification they will check to see if your program can handle that scenario. When you start Location services you can then see if it is disabled.
watcher.Start();
bool IsLocationServicesTurnedOff = (watcher.Permission == GeoPositionPermission.Denied);
Also remember that in Mango your program can be suspended, location services disabled, and your program reactivated. In other words location services can perceivable be disabled at any time during the life of your program.
The following piece of test code runs under Windows Mobile.
It's objective is to seek out the default message store so I can get the proper account name for programmatically compiling an email.
IMAPISession *mapiSession;
HRESULT hr = S_OK;
MAPIInitialize (NULL);
IMAPITable *msgTable;
SRowSet *pRows;
IMsgStore *msgStore;
if (MAPILogonEx(0,NULL,NULL,0,&mapiSession) != S_OK)
{
// MessageBox(g_hWnd,_T("Failed to logon"),_T("Error"),0);
}
else
{
SizedSPropTagArray(3, PropTagArr) = {3,{PR_DISPLAY_NAME,
PR_ENTRYID,
PR_DEFAULT_STORE}};
hr = mapiSession->GetMsgStoresTable(MAPI_UNICODE,&msgTable);
hr = msgTable->SetColumns((LPSPropTagArray)&PropTagArr, 0);
if (!hr)
{
do
{
hr = msgTable->QueryRows(1,0,&pRows);
LPSPropValue lpProp;
lpProp = &pRows->aRow[0].lpProps[0];
// if(_tcscmp( lpProp->Value.LPSZ, _T("SMS") ) == 0 )
// break;
lpProp = &pRows->aRow[0].lpProps[0];
if (lpProp->ulPropTag == PR_DEFAULT_STORE)
break;
lpProp = &pRows->aRow[0].lpProps[1];
if (lpProp->ulPropTag == PR_DEFAULT_STORE)
break;
lpProp = &pRows->aRow[0].lpProps[2];
if (lpProp->ulPropTag == PR_DEFAULT_STORE)
break;
FreeProws(pRows);
pRows = NULL;
}while (!hr);
hr = mapiSession->OpenMsgStore (0,
pRows->aRow[0].lpProps[1].Value.bin.cb,
(ENTRYID*)pRows->aRow[0].lpProps[1].Value.bin.lpb,
NULL,
MDB_NO_DIALOG | MAPI_BEST_ACCESS,
&msgStore);
... BUT, fails to get the PR_DEFAULT_STORE property on a Windows Mobile device. I'm guessing Microsoft didn't implement it accurately. And so, lpProp->ulPropTag will never == PR_DEFAULT_STORE. It's always 0000.
Has anyone had success getting PR_DEFAULT_STORE using MAPI under Windows Mobile?
Is there another way of the determining the default message store?