Im trying to develop a blackberry native app, whose function is to lock the device. Is it possible to set the device lock state? should i use any third party api?
I found this java code..
ApplicationManager appman = ApplicationManager.getApplicationManager();
appman.lockSystem(true);
Anything similar in c++?
No. Is not possible with the current API.
You should use some trick such as show a dialog window or other.
You can do is understand the state of the device using the code below.
if (myHomeScreen.lockState == DeviceLockState.Unknown) {
console.log("No idea");
} else if (myHomeScreen.lockState == DeviceLockState.Unlocked) {
console.log("Unlocked");
} else if (myHomeScreen.lockState == DeviceLockState.ScreenLocked) {
console.log("Screen locked");
} else if (myHomeScreen.lockState == DeviceLockState.PasswordLocked) {
console.log("Password locked");
} else if (myHomeScreen.lockState == DeviceLockState.PinBlocked) {
console.log("PIN blocked");
}
This is an extract of this documentation.
Related
My project is Xamarin Forms in iOS device, and that using WIFI to work with other devices. I want to know whether it is possible to know the current connected ssid name first. If my app loses the link, can it silently try to reconnect to the WiFi without the user having to do anything?
Here is my logic diagram
You could use DependencyService to get a SSID name, you could refer to Xamarin.Forms DependencyService
In your service, try some code like this:
string ssid = "";
string[] supportedInterfaces;
StatusCode status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces);
if ((status = CaptiveNetwork.TryGetSupportedInterfaces(out supportedInterfaces)) == StatusCode.OK)
{
foreach (var item in supportedInterfaces)
{
NSDictionary info;
status = CaptiveNetwork.TryCopyCurrentNetworkInfo(item, out info);
if (status == StatusCode.OK)
{
ssid = info[CaptiveNetwork.NetworkInfoKeySSID].ToString();
}
}
}
In your info.plist, you should add this key:
<key>NSLocationWhenInUseUsageDescription</key>
<string>Your Description</string>
Once you get the SSID name (and password), you could use NEHostspotConfiguration to make a connection.
NEHotspotConfiguration hotspotConfiguration = new NEHotspotConfiguration(ssid,pwd,false);
hotspotConfiguration.JoinOnce = true;
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(hotspotConfiguration, (NSError error) =>
{
if (error != null)
{
if (error?.LocalizedDescription == "already associated.")
{
IsConnected = true;
}
else
{
IsConnected = false;
}
}
else
{
IsConnected = true;
}
});
You may also enable Access WiFi information, Hotspot capability of you App ID at the Apple Developer Portal and add them in your Entitlements.plist. Don't forget to regenerate your provisioning file. Hope my answer could help you~
How can I get the CBUUID from the device that my app is currently running on? I'm using Xamarin but answer in objective-c or swift would be good too.
use Plugin.BLE (https://www.nuget.org/packages/Plugin.BLE/)
foreach(AdvertisementRecord record in e.Device.AdvertisementRecords)
{
if (record.Type == AdvertisementRecordType.UuidsComplete128Bit || record.Type == AdvertisementRecordType.UuidsComplete16Bit)
{
b.ServiceUUID = record.Data;
break;
}
}
Then
foreach(Beacon beacon in beaconList)
{
cbuuidList.Add(CBUUID.FromBytes(beacon.ServiceUUID));
}
CBUUID[] uuid = cbuuidList.ToArray();
BLEManager.ScanForPeripherals(uuid);
detail here: https://forums.xamarin.com/discussion/92838/proper-way-to-retrieve-uuid-of-device
I try to implement Mixpanel's tweaks into my app for A/B testing. This is my code:
if (MPTweakValue(kFeaturedOffersTweak, NO)) {
return MenuItemRowHeight;
}
else {
return 0;
}
On the first lunch everything is OK and tweak value is YES. Then I switch off internet on my iPhone, open run again and tweak value is NO.
What is correct way to use Mixpanel's tweak without internet?
So, I created my custom manager, where I implemented tweaks' persistency.
Please, let me know, if you have better solution.
My code:
-(void)initManager {
[[Mixpanel sharedInstance] joinExperimentsWithCallback:^{
USE_SETTINGS;
SETTINGS_SETBOOL(kPreferredPartnersTweak, MPTweakValue(kPreferredPartnersTweak, NO));
SYNCHRONIZE_SETTINGS;
//===
SEND_NOTIF(kTweaksUpdated, nil);
}];
}
-(BOOL)getTweakWithName:(NSString*)tweakName {
BOOL result = NO;
//===
USE_SETTINGS;
if (SETTINGS_BOOL(tweakName)) {
result = SETTINGS_BOOL(tweakName);
}
else {
result = MPTweakValue(kPreferredPartnersTweak, NO);
}
//===
return result;
}
USE_SETTINGS, SETTINGS_BOOL, SYNCHRONIZE_SETTINGS is my macros wrappers for working with NSUserDefaults.
I want to know what is the way to enable and disable internet connection in blackberry through coding.
EDIT
protected void disableConnection() {
activeConn = RadioInfo.getActiveWAFs();
if(activeConn == 0){
activeConn = RadioInfo.getEnabledWAFs();
}
mystore.setContents(new Integer(activeConn));
mystore.commit();
Radio.deactivateWAFs(activeConn);
Dialog.alert("Off internet");
}
protected void enableConnection() {
if(RadioInfo.getState() == RadioInfo.STATE_ON){
Dialog.alert("Internet on already");
}else if(mystore.getContents() != null){
if(Radio.activateWAFs(Integer.parseInt(mystore.getContents().toString())) == true){
Dialog.alert("On Internet");
}else{
Dialog.alert("Unable to on internet");
}
}else{
Dialog.alert("Unable to on internet");
}
}
These are two methods which I call on turn on and turn off button click.
You asked about internet connectivity, so I assume you are interested in more than just the Wi-Fi connection. Calling Radio.deactivateWAFs(RadioInfo.WAF_WLAN); will only disable Wi-Fi.
A better implementation would probably first check which radios are on, and then turn those radios off. When you want to turn service on again, reactivate the radios which you turned off. Something like this:
/** we record which radios are active */
private int _activeWAFs = 0;
private void getActiveWAFs() {
_activeWAFs = RadioInfo.getActiveWAFs();
if (_activeWAFs == 0) {
_activeWAFs = RadioInfo.getEnabledWAFs();
}
}
/** turn radios off if they're currently on */
private void disableAll() {
getActiveWAFs();
Radio.deactivateWAFs(_activeWAFs);
}
/** turn radios on, if we turned them off with disableAll() */
private void enableAll() {
boolean success = Radio.activateWAFs(_activeWAFs) && (RadioInfo.getState() == RadioInfo.STATE_ON);
if (!success) {
// do something?
}
}
Also, if you want notifications about the results of these operations, or external changes to the radio, you can implement RadioStatusListener:
public void networkStarted(int networkId, int service) {
if (RadioInfo.getState() == RadioInfo.STATE_ON) {
// network ready to use!
}
}
And, yes, this call will affect the entire device, not just internet connectivity for your app.
Radio.deactivateWAFS() will it deactivate all the wireless connection or just internet connectivity or Bluetooth connectivity.
Example: deactive WiFi connectivity.
Radio.deactivateWAFs(RadioInfo.WAF_WLAN);
try this -
this will turn on wifi-
Radio.activateWAFs(RadioInfo.WAF_WLAN);
this will turn off the wifi-
Radio.deactivateWAFs(RadioInfo.WAF_WLAN);
I'd like my user to take a picture as an attachment by using the built in camera.
Is there someway to invoke the camera on a button press and save the resulting taken picture?
The other option is to use the BlackBerry Invoke API to start the native camera application and listen for a file system event:
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
then, later:
class FileExplorerDemoJournalListener implements FileSystemJournalListener {
public void fileJournalChanged() {
long nextUSN = FileSystemJournal.getNextUSN();
for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) {
FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
if (entry == null) {
break;
}
String path = entry.getPath();
if (path != null) {
if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){
switch (entry.getEvent()) {
case FileSystemJournalEntry.FILE_ADDED:
//either a picture was taken or a picture was added to the BlackBerry device
break;
case FileSystemJournalEntry.FILE_DELETED:
//a picture was removed from the BlackBerry device;
break;
}
}
}
}
}
}
Finally...
Application.addFileSystemJournalListener(new FileExplorerDemoJournalListener());
This will get you most of the way there... taken from: http://docs.blackberry.com/en/developers/deliverables/11942/Detect_when_img_is_added_or_removed_file_system_740288_11.jsp
http://docs.blackberry.com/en/developers/deliverables/17968/Take_a_picture_in_a_BB_device_app_1228201_11.jsp