How to detect network in Blackberry 10 Dev Alpha Simulator using qnx.net.NetworkManager on Air SDK - air

I'm trying to detect internet connection of the simulator using this code
if (
NetworkManager.networkManager.isConnected(NetworkType.WIFI) ||
NetworkManager.networkManager.isConnected(NetworkType.CELLULAR)
) {
//we have connection!!
doSomething();
} else {
//no connection =(
showError();
}
However, this always returns false. It seems that the simulator uses another kind of network not identified by NetworkType constants. I think this happens because VMWare makes connection possible through black magic.
So i am not sure if I should stick to this code and hope it will work in a real device using WiFi or Cellular network, or should find another approach for what I need.
I've also tried doing this (passing no parameters)
NetworkManager.networkManager.isConnected()
but it will always return true despite if I have internet connection or not in my PC. I think VMWare is trolling me again.
So, any advice on how should I do this for better results in a real device?

Well, just to update. I finally got a BBZ10, and had a chance to try this code. It seems that
NetworkManager.networkManager.isConnected(NetworkType.WIFI)
and
NetworkManager.networkManager.isConnected(NetworkType.CELLULAR)
will work the way they are expected, even if the emulator can't really emulate their funcionality.
So, if you really need this functionality, go ahead and try this, it WILL really work once deployed.

Related

Requesting runtime permissions in Kotlin

I have a MVVM app, which needs Bluetooth through the entire app. The only screen that doesn't require Bluetooth is the Onboarding screen. In the first screen, the app starts automatically searching for devices, which requires BLUETOOTH_SCAN to function properly. I have attempted numerous things to request the runtime permissions and check if the Bluetooth is on, but nothing seemed to work. I'd greatly appreciate any help.
I have tried calling the functions in the onResume() of the activity, but it slows down the app a significant lot. I have also tried requesting the permissions when the startScan() function gets called, but that seems to crash, because in order to start the scan I need to have the permissions allowed and the bluetooth adapter should be initialized, a.k.a Bluetooth should be turned on
Did you had a look at this Answer?
https://stackoverflow.com/a/69972855/20356055
It describes very good how to request the bluetooth permissions.
And don't forget to add the permissions in the manifest ;)

Serial communication with Xtralien potentiostat not working?

I am trying to set up a potentiostat Xtralien by Ossila with LabView.
The way the instrument works in a string-in, string-out, so far so good.
The built-in code examples that are provided by the manufacturer contain firstly a string-in, string-out LabView program and secondly a preliminary console to record an I-V sweep (https://www.ossila.com/pages/basic-xtralien-commands-in-labview, https://www.ossila.com/pages/xtralien-x100-command-list). In the string interface, I can enter 'CLOI hello' and the device responds 'hello world', so far so good. If I proceed any further and send i.e. a 'smu1 measurev' command connecting to some photodiode, I just receive a near-zero value back, setting 'smu1 set voltage 0.5' or similar does not lead to an output voltage either. Running the sweep program over said photodiode gives noise in the µA range.
EDIT: All involved hardware components were double-checked.
Where am I doing something wrong? Is the error arising from communication errors or...? Has someone experienced this so far?
Received the answer from the Ossila support. The Xtralien X200 drivers were recently updated (http://files.ossila.com/source-measure-unit/Ossila-X200-SMU-Instr.zip), and you need to switch on each SMU channel sperately. This was implemented in a subVI in the Instrumentation -> X200.
Hope I helped all who get a similar problem in the future!

Flash player API for browser extension

let's say we have a P2P multi-player Flash based game hosted on a website. Would it be possible to create a browser extension that would listen to what is going on within the Flash application? For example, I would like to know when a player connects to a room, gets kicked or banned, or simply leaves by himself. I'm sorry this is not really a specific question but I need a direction to start. Thanks in advance!
I can see a few ways to communicate between Flash and a browser plugin.
One is to open a socket to a server running on the local machine. Because of the security sandbox, this may not be the easiest approach, but if feasible, it is of course probably the one to go for because you've already got your socket-handling code written, and listening/writing to a additional socket isn't terribly complicated. For this approach, you just need your plugin to start listening on a socket, and get the flash applet to connect to it.
Another way might be to try something with passing messages in cookies. Pretty sure this would just cause much grief, though.
Another way, and I suspect this may turn out to be the easier path, is to communicate between Flash and JavaScript using the ExternalInterface class, then from JavaScript to the plugin. Adobe's IntrovertIM example should get you started if you can find a copy on the web.
In Flash, create two functions, a jsToSwf(command:String, args:Array<String>):Dynamic function, to handle incoming messages from JS that are sent to that callback, and a swfToJs(command:String, args:Array<String> = null):Dynamic function, which calls flash.external.ExternalInterface.call("swfToJs", command, args);.
To set it up, you need to do something like:
if (flash.external.ExternalInterface.available) {
flash.external.ExternalInterface.addCallback("jsToSwf", jsToSwf);
swfToJs("IS JS READY?");
}
(The two parameters to addCallback are what the function is called in JS, and what it's called in Flash. They don't have to be the same thing, but it sort of makes sense that they do)
In JS, you need the same functions: function swfToJs(command, params) accepts commands and parameter lists from Flash; and jsToSwf(command, params) calls getSwf("Furcadia").jsToSwf(command, params);.
getSwf("name") should probably be something like:
/** Get ref to specified SWF file.
// Unfortunately, document.getElementById() doesn't
// work well with Flash Player/ExternalInterface. */
function getSwf(movieName) {
result = '';
if (navigator.appName.indexOf("Microsoft") != -1) {
result = window[movieName];
} else {
result = document[movieName];
}
return result;
}
The only fiddly bit there is that you need to do a little handshake to make sure everyone's listening. So when you have Flash ready, it calls swfToJs("IS JS READY?"); then the JS side, on getting that command, replies with jsToSwf("JS IS READY!"); then on getting that, Flash confirms receipt with swfToJs("FLASH IS READY!"); and both sides set a flag saying they're now clear to send any commands they like.
So, you've now got Flash talking with JS. But how does JS talk with a browser extension? And, do you mean extension, or add-on, since there's a difference! Well, that becomes a whole 'nother can of worms, since you didn't specify which browser.
Every browser handles things differently. For example, Mozilla has port.emit()/port.on() and the older postMessage() as APIs for JS to communicate with add-ons.
Still, I think ExternalInterface lets us reduce a hard question (Flash-to-external-code comms) to a much simpler question (Js-to-external-code comms).

Checking whether spoken commands are enabled?

Is there a way to check whether the user has enabled speech recognition (spoken commands) in System Preferences? (Mac OS X). If the user has it enabled, I would like to support additional speech commands. Unfortunately there isn't any method in NSSpeechRecognizer to check this and I can't seem to find any Carbon functions to check it either.
One of the problem is that the round Speech Commands window (the one with a microphone on it) seems to appear intermittently whenever I instantiate NSSpeechRecognizer. Also it often freezes my app for about half a second or so while the object is created (probably it's starting up the speech recognition service).
In essence, if the speech recognizer isn't already running and being used, I don't want to start it up. But if the user actively uses the speech recognizer, I would like to provide additional support for it.
Thanks in advance.
I don't know the public API either; but the round mic window is controlled by SpeakableItems.app, at least on OS X 10.6. You can check the process list and/or the running applications list to see if it's there.
As inspired by #Yuji's answer, looks like the only way is to check whether the speech recognition server is running or not. Here is the code snippet, in case anyone also need it.
+(BOOL) speakableItemsEnabled {
NSString* speechServerBundleName = #"com.apple.speech.recognitionserver";
NSArray* apps = [NSRunningApplication runningApplicationsWithBundleIdentifier:speechServerBundleName];
NSRunningApplication* speechServerApp = [apps lastObject];
return speechServerApp && !speechServerApp.terminated;
}
Hopefully this doesn't break in 10.7 "Lion".

Android HTC Desire Voice input issues

Would anyone have an idea as to why an app would work on almost every phone that has 2.1 but not the Desire?
One of my apps uses voice input and the Desire is the only phone that force closes when the voice prompt comes up.
The worst part is that I don't know how to test this, I don't have one or know anyone who does.
Any ideas?
EDIT:
I finally found out that HTC disabled voice in the Desire and you have to do a work around to install it.
So if you are relying on voice input make sure you use the code in the google example to catch the error:
PackageManager pm = getPackageManager();
List<ResolveInfo> activities = pm.queryIntentActivities(
new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0);
if (activities.size() == 0) {
noResults.setText("Voice input not found on this phone.");
}else{
//If voice is enabled
}
I think the most important thing to do first is to get the exception report. Since you can't test it by yourself, I would use a tool to get the exception report from your customers. In Android 2.2 the built-in tool can be used. If you have other targeting SDKs I would recommend this services: http://code.google.com/p/android-remote-stacktrace/ to get a remote stacktrace.
Then if you post the stacktrace here, I think somebody will be able to help you!