How to check if data connected or not in Android and ios using codenameOne - codenameone

The following code is working fine for Android Devices bt it doesn't works in ios using codenameOne.
public static boolean checkNetwork(){
boolean online = false;
String net = NetworkManager.getInstance().getCurrentAccessPoint();
if (net == null || net == "" || net.equals(null)) {
online = false;
} else {
online = true;
}
return online;
}
Note : It seems No Connection Error Even data was connected to ios device

There is a CN1 library written by LittleMonkey that you can use to check connectivity. Search for connectivity in Codename One Extensions and download it to your project.
You can check for connection like this:
if (Connectivity.isConnected()) {
//we have some connection
} else {
// we have no connection
}
And you can check what type of connection
ConnectionState status = Connectivity.getConnectionState();
switch (status) {
case DISCONNECTED:
Log.p("Disconnected");
break;
case WIFI:
Log.p("On Wifi");
break;
case MOBILE:
Log.p("On Mobile Data");
break;
default:
//shouldn't be possible
}
Read more about this on GitHub.

Related

Pinging many devices at same time cause a timeout?

Similar to other ping questions here, we need to ping many IP addresses at the same time. We thought we had it running great after following many responses and examples from here, however we are experiencing failed pings due to timeout when we attempt to ping them at the same time, or even close together.
We tested our list of IP's on another ping monitoring program and the timeout does not happen. The issue is specific to our application.
In our application, every "device" has a RouterProperties class that holds its Name, IP Address, etc. We ping from the observable collection of these devices, getting their IP addresses from their RouterProperties.
Tested separating pings by 10(ms)/20(ms) await task.delay
Tested separating pings by 10(ms)/20(ms) using a dispatcher timer
Tested pinging all at once with no delay between, causing largest amounts of timeouts.
Tested converting IP Address "strings" to IP Address before pinging, no visible change in issue.
Tested with ping timeout at 500(ms), 1000(ms), 5000(ms), etc.
Current test is for 143 devices, but needs to be able to handle more.
//OUR MAIN PING SCHEDULER
private async void PingAllDevices(object sender, EventArgs e)
{
var allPingTasks = new List<Task>();
int numOfDevices = 1;
//Assign a task to each device.
foreach (RouterProperties device in devices)
{
await Task.Delay(10);
Console.WriteLine("Pinging device #" + numOfDevices + " : " + device.RouterIP);
numOfDevices++;
allPingTasks.Add(AsyncPingDevice(device));
}
//Block here for all created tasks.
await Task.WhenAll(allPingTasks);
}
}
//OUR PING TASK
async Task AsyncPingDevice(RouterProperties device)
{
// Get device IP address to ping.
string deviceIP = device.RouterIP;
try
{
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
var reply = await pingSender.SendPingAsync(deviceIP, (int.Parse(Properties.Settings.Default.PingTimeout)), buffer, pingOptions);
Console.WriteLine(deviceIP + " has responded.");
if (reply.Status == IPStatus.Success)
{
device.PingCounter = 0;
}
else
{
if (device.PingCounter <= 3)
{
device.PingCounter++;
}
}
}
catch
{
if (device.PingCounter <= 3)
{
device.PingCounter++;
}
}
await Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action( () =>
{
if (device.IsDeactivated != true)
{
switch (device.PingCounter)
{
case 0:
device.Color = "#FF8AA587";
break;
case 1:
device.Color = "#FF9AB999";
break;
case 2:
device.Color = "#FFFCCEAA";
break;
case 3:
device.Color = "#FFF4837D";
break;
case 4:
device.Color = "#FFEB4960";
break;
}
}
}));
}
When we run our code, with and without the task.delay inside the ping scheduler to separate the pings, we end up with inconsistent results from the devices being pinged.
Without the delay = 75% of all devices timeout.
With the delay = inconsistently random 10% of devices timing out per
cycle.
Similar ping program to ours = 100% consistent results without any
timeouts.

LABiometryType in iOS11 always return None

No matter what settings is configured in Device's passcode and touchId settings , LAContext always returns none . It is just throwing me a warning not the exception.
Its only working in XCode 9.1 Beta in iOS11.1 beta as suggested :(
I just figured out the problem! You have to call canEvaluatePolicy for biometryType to be properly set.
Example:
func isFaceIdSupported() -> Bool {
if #available(iOS 11.0, *){
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil) {
return context.biometryType == LABiometryType.typeFaceID
}
}
return false
}
As per the Apple docs for biometryType:
"This property is only set when canEvaluatePolicy(_:error:) succeeds for a biometric policy. The default value is none."
If you use the code from #Ermish, isFaceIdSupported() will return false if there are no enrolled faces on the device.
As per my latest tests shows on iOS SDK 11.1, just call the laContext.canEvaluatePolicy function and do not care about the result, then check the content of laContext.biometryType.
If there are no enrolled faces, the canEvaluatePolicy will fail, but the device supports Face ID.
Got the same issue here, fixed it with the following code. But it only works with the Xcode 9.1 Beta (and iOS 11.1 beta in the simulator).
if (laContext.canEvaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, error: nil)) {
if #available(iOS 11.0, *) {
if (laContext.biometryType == LABiometryType.faceID) {
print("FaceId support")
} else if (laContext.biometryType == LABiometryType.touchID) {
print("TouchId support")
} else {
print("No Biometric support")
}
} else {
// Fallback on earlier versions
}
}
In Xamarin.iOS, you need evaluate the Policy Before:
NSError error;
bool success = context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out error);
if (context.BiometryType == LABiometryType.TouchId)
{
//Do Something
}

Cisco Call Manager JTAPI support for SIP protocol

I am trying to monitor SIP devices located on Cisco Call manager via JTAPI. I have installed JTAPI plugin and try to run its sample makeCall scenario.
CUCM version : 9.1.2.10000-28
When I list the controlled device addresses of the provider, it only returns devices with SCCP protocol (skinny phones) but not return devices with SIP device protocol. There are already SIP based devices added into the controlled device list of the provider on CUCM.
JtapiPeer peer = JtapiPeerFactory.getJtapiPeer(null);
/* connect to the provider */
String providerString = hostname;
providerString += ";login=" + login;
providerString += ";passwd=" + passwd;
Provider provider = peer.getProvider(providerString);
/* wait for it to come into service */
final Condition inService = new Condition();
provider.addObserver(new ProviderObserver() {
public void providerChangedEvent (ProvEv [] eventList) {
if (eventList == null) return;
for (int i = 0; i < eventList.length; ++i) {
if (eventList[i] instanceof ProvInServiceEv) {
inService.set();
}
}
}
});
inService.waitTrue();
for(Address address : provider.getAddresses()){
System.out.println(address.getName());
}
Is there any other config, etc.. that I need to do in order to list SIP phones as well?
Thanks.
JTAPI applications can only control Cisco Unified IP Phone 7900 Series that run SIP, which includes Cisco Unified IP 7970 phones. Which model you are using?
http://www.cisco.com/c/en/us/td/docs/voice_ip_comm/cucm/jtapi_dev/9_1_1/jtapidevguide/featsupported.html#wp1148307

How to retrieve IMSI using PhoneGap?

I'm working on a cross platform mobile app using PhoneGap and I need to retrieve the IMSI code.
Here's the question: Is there any way to do this via PhoneGap?
I appreciate your comments.
hi for android we can find via native code , for phonegap we need to write a plugin, java code is given bellow
public String findDeviceID() {
String deviceID = null;
String serviceName = Context.TELEPHONY_SERVICE;
TelephonyManager m_telephonyManager = (TelephonyManager) getSystemService(serviceName);
int deviceType = m_telephonyManager.getPhoneType();
switch (deviceType) {
case (TelephonyManager.PHONE_TYPE_GSM):
break;
case (TelephonyManager.PHONE_TYPE_CDMA):
break;
case (TelephonyManager.PHONE_TYPE_NONE):
break;
default:
break;
}
deviceID = m_telephonyManager.getDeviceId();
return deviceID;
}
for creating phonegap plugin check this http://docs.phonegap.com/en/edge/guide_platforms_android_plugin.md.html#Android%20Plugins

Is there anyway to know which user is calling the WCF Ria service on server side, using silverlight on clientside?

Is there anyway to know which user is calling the WCF Ria service on server side? Client side is siverlight, user has to be authenticated first in order to use the system.
I need to know which user is actually calling the service in my current task, thanks, i searched a lot, but seems no good findings.
Once the client side has successfully cleared your authentication challenge, the server can issue a token to the caller on the client side. In subsequent calls to the server, the client would send the token as one of the arguments and the server would verify the token and respond accordingly.
The token can contain a segment of information that identifies a given user, and implementing this will provide the functionality you are seeking.
The only guidelines for generating tokens is that they are unique, non-predictable and expirable. I have always encrypted my tokens so that they appear as gibberish, but step this is optional.
I've also done very much "googleing" and got a lot of headache before I got the solution.
I don't use RIA-Services - but it should be (hopefully) the same...:
The SL-Client sends a "login-request" to the server.
On the (WCF) server-side, I do the following (LoginData = Return-Info for SL-Client):
public LoginData LoginRequest() {
(...)
OperationContext context = OperationContext.Current;
System.ServiceModel.Channels.MessageProperties prp = context.IncomingMessageProperties;
System.ServiceModel.Channels.RemoteEndpointMessageProperty endPrp = prp[System.ServiceModel.Channels.RemoteEndpointMessageProperty.Name] as System.ServiceModel.Channels.RemoteEndpointMessageProperty;
(...)
try {
clientIP = endPrp.Address;
System.Net.IPAddress ipAddress = System.Net.IPAddress.Parse(clientIP);
System.Net.IPHostEntry ipHostEntry = System.Net.Dns.GetHostEntry(ipAddress);
(...)
If you want to check the users WindowsPrincipal, you can do the following (securityGroup = server-side setting, which users can login):
(...)
switch (securityGroup) {
case SecurityGroup.AllClientsCanAccess: {
clientCanLogin = true;
} break;
case SecurityGroup.UseWindowsCredentials: {
if (OperationContext.Current.ServiceSecurityContext != null && OperationContext.Current.ServiceSecurityContext.WindowsIdentity != null) {
if (OperationContext.Current.ServiceSecurityContext.WindowsIdentity.IsAuthenticated) {
if (subSecurityInfo1 == true) { // only clients in specific roles can log in
bool userRoleFound = false;
WindowsPrincipal userPrincipal = new WindowsPrincipal(OperationContext.Current.ServiceSecurityContext.WindowsIdentity);
if (userPrincipal == null)
break;
foreach (string userRoleToPass in subSecurityList) { // subSecurityList = settings, which roles can pass
loginError.ErrorInfo += string.Format("{0}\n", userRoleToPass);
if (userPrincipal.IsInRole(userRoleToPass)) {
clientCanLogin = userRoleFound = true;
break;
}
}
if (userRoleFound) {
loginError.ErrorInfo = string.Empty;
break;
}
else {
loginError.ErrorNo = LoginErrorCodeNoEnum.UserIsNotInRole;
}
}
(...)
Hope it helps...

Resources