Enable/Disable Location Worklight - geolocation

I need to disable/enable location service on button click (IOS & Android). I am using Worklight V6.2. hope there is solution.

For Starting The Location Service use the API
WL.Device.StartAcquisition
For Stopping The Location Service use the API
WL.Device.StopAcquisition
More Info Regarding Start and Stop Acquisition services
Note:API are same for IOS/Android/Windows8

Follow this excellent Tutorial for using service..
To start and stop the service create 2 buttons in your xml page,and in java
btnShowLocation = (Button) findViewById(R.id.Start);
btnStopLocation = (Button) findViewById(R.id.stop);
btnShowLocation.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
startService(intent);
}
}
btnStopLocation.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View arg0)
{
stopService(intent);
}
}
But its a very lengthy task..Hope you will get some idea on how to achieve this task.All the best..

Related

How do you send message using NFC with Xamarin.Android?

I am developing and app to demostrate how NFC works. My goal is to make and app that will work very similary to Android Beam. I am using Xamarin.Android. The goal is to type message to one device, press button and it should be send to another device with the same app where it should be shown. I have tried almost everything even the documentation but it seems like it doesnt work. Does anyone have any experience with this technology? Is this technology even available nowadays?
There is some of my code to get you an idea about what i am trying to do:
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
SetContentView(Resource.Layout.activity_main);
mNfcAdapter = NfcAdapter.GetDefaultAdapter(this);
myButton.Click += (e, o) => {
mNfcAdapter.SetNdefPushMessageCallback(this, this);
mNfcAdapter.SetOnNdefPushCompleteCallback(this, this);
};
}
public NdefMessage CreateNdefMessage(NfcEvent e)
{
DateTime time = DateTime.Now;
var text = (time.ToString("HH:mm:ss") + message2);
NdefMessage msg = new NdefMessage(
new NdefRecord[] { CreateMimeRecord (
text, Encoding.UTF8.GetBytes (text))});
return msg;
}
private NdefRecord CreateMimeRecord(string mimeType, byte[] payload)
{
byte[] mimeBytes = Encoding.UTF8.GetBytes(mimeType);
NdefRecord mimeRecord = new NdefRecord(
NdefRecord.TnfMimeMedia, mimeBytes, new byte[0], payload);
return mimeRecord;
}
public void OnNdefPushComplete(NfcEvent e)
{
Toast.MakeText(this.ApplicationContext, "Message sent", ToastLength.Long).Show();
}
protected override void OnResume()
{
base.OnResume();
if (NfcAdapter.ActionNdefDiscovered == Intent.Action)
{
ProcessIntent(Intent);
}
}
protected override void OnNewIntent(Intent intent)
{
Intent = intent;
}
void ProcessIntent(Intent intent)
{
IParcelable[] rawMsgs = intent.GetParcelableArrayExtra(
NfcAdapter.ExtraNdefMessages);
NdefMessage msg = (NdefMessage)rawMsgs[0];
var textViewMsg = FindViewById<TextView>(Resource.Id.textViewMsg);
textViewMsg.Text = Encoding.UTF8.GetString(msg.GetRecords()[0].GetPayload());
}
Thank you all :)
OnNdefPushComplete and the whole Android Beam was deprecated and removed from Android 10
https://developer.android.com/reference/android/nfc/NfcAdapter.OnNdefPushCompleteCallback
If you want to do Device to Device NFC going forward then it should be possible with one phone doing Host Card Emulation (HCE) and the other using enableReaderMode
But Google recommend using Bluetooth or Wifi Direct as a more reliable replacement for Android Beam. One of the replacement methods Google provided was Android Nearby https://developers.google.com/nearby

Why BiometricPrompt API in Xamarin Android doesn't contain onAuthenticationError Callback

In Android Studios BiometricPrompt API contains a callback named onAuthenticationError which gets triggered when the user touch outside the BiometricPrompt dialog and once a user tries to input an invalid Biometric to the device. But the BiometricPrompt API available in Xamarin.Android platform doesn't provide onAuthenticationError callback.
I created an android application using Android Studios to check BiometricPrompt API there I could access the callback named onAuthenticationError. Then I deployed the application to a device and debugged the application. The above mentioned callback got triggered when I touched any area outside the BiometricPrompt dialog and it also got triggered every time I provided BiometricPrompt with a invalid input more than 5 times.
Then I tried developing the same application in Xamain.Android and there I was unable to find any callback named onAuthenticationError. When I deployed and tested the application in a device as the above-mentioned callback was not available I couldn't handle the 2 scenarios
where when the user touches any area outside the BiometricPrompt dialog and when user provides the BiometricPrompt with an invalid input more than 5 times.
My Native android code snippet.
#RequiresApi(api = Build.VERSION_CODES.P)
private BiometricPrompt.AuthenticationCallback getAuthenticationCallback() {
return new BiometricPrompt.AuthenticationCallback() {
#Override
** public void onAuthenticationError(int errorCode,
CharSequence errString) {
notifyUser("Authentication error: " + errString);
super.onAuthenticationError(errorCode, errString);
}**
#Override
public void onAuthenticationHelp(int helpCode,
CharSequence helpString) {
super.onAuthenticationHelp(helpCode, helpString);
}
#Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
#Override
public void onAuthenticationSucceeded(
BiometricPrompt.AuthenticationResult result) {
notifyUser("Authentication Succeeded");
super.onAuthenticationSucceeded(result);
}
};
}
My Xamarin.Android code snippet
public class BiometricAuthCallBacks : BiometricPrompt.AuthenticationCallback
{
public TaskCompletionSource<LocalAuthStatus> promise = new TaskCompletionSource<LocalAuthStatus>();
private int failCount;
public override void OnAuthenticationSucceeded(BiometricPrompt.AuthenticationResult result)
{
base.OnAuthenticationSucceeded(result);
promise.TrySetResult(LocalAuthStatus.Success);
//Success(result);
}
public override void OnAuthenticationFailed()
{
base.OnAuthenticationFailed();
failCount++;
if (failCount>=5)
{
promise.TrySetResult(LocalAuthStatus.Fail);
}
//Failed();
}
public override void OnAuthenticationHelp([GeneratedEnum] BiometricAcquiredStatus helpCode, ICharSequence helpString)
{
base.OnAuthenticationHelp(helpCode, helpString);
promise.TrySetResult(LocalAuthStatus.Error);
//Help(helpCode, helpString);
}
}
My Question is why can't I access onAuthenticationError callback from Xamarin.Android platform and how can I resolve this?

Twitter Login crash

I am developing an app with Twitter login. When I am checking Fabric, it doesn't contain Twitter login as it's no longer available via Fabric, so I am trying to implement it using Twitter Kit (Twitter Kit Link).
I have installed Twitter Kit on my app, when I am trying to run the app it crashes on
Twitter.sharedInstance().startWithConsumerKey(<key>, consumerSecret: <secret>)
Error: terminating with uncaught exception of type NSException
Any solutions...
try this code
add this gradle line in you project
compile 'com.twitter.sdk.android:twitter:3.0.0'
Write in your Activity/Fragment
//Your Custom Button
private ivTwitter;
//Twitter Login Button
private TwitterLoginButton ivTwitterMain;
//init twitter
TwitterConfig config = new TwitterConfig.Builder(this)
.logger(new DefaultLogger(Log.DEBUG))
.twitterAuthConfig(new TwitterAuthConfig(Const.CONSUMER_KEY, Const.CONSUMER_SECRET))
.debug(false)
.build();
Twitter.initialize(config);
//find your button
ivTwitter = (ImageView) findViewById(R.id.ivTwitter);
ivTwitterMain = (TwitterLoginButton)findViewById(R.id.ivTwitterMain);
//twitter login callback
ivTwitterMain.setCallback(new Callback<TwitterSession>() {
#Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
TwitterSession session = TwitterCore.getInstance().getSessionManager().getActiveSession();
TwitterAuthToken authToken = session.getAuthToken();
String token = authToken.token;
String secret = authToken.secret;
getTwitterUserProfile(session);
}
#Override
public void failure(TwitterException exception) {
// Do something on failure
Log.d(Const.FRAGMENT_REGISTER, exception.getMessage());
}
});
getTwitterUserProfile code
private void getTwitterUserProfile(TwitterSession session) {
AccountService accountService = new TwitterApiClient(session).getAccountService();
Call<User> callback = accountService.verifyCredentials(true, true, true);
callback.clone().enqueue(new Callback<User>() {
#Override
public void success(Result<User> result) {
Log.d("NAME ", result.data.name);
Log.d("EMAIL", result.data.email);
Log.d("PICTURE ", result.data.profileImageUrl);
}
#Override
public void failure(TwitterException exception) {
}
});
}
at last generate Click event of custom button
ivTwitter.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//twitter login button
ivTwitterMain.performClick();
}
});
I'm assuming that you have already read the twitter official documentation about "Installation" of the TwitterKit in iOS app. I had such experience and the only thing that worked and wasn't in the documentation was this:
In your Info.plist file make sure that "twitterkit-yourAppKey" in
your CFBundleURLSchemes is Item 0.
I've answered this here. Hope it helps you :)

BlackBerry App: Screen Not Showing Up In Auto Run Mode

I am trying to create a background app which will run at system startup. When I run it manually (from the ribbon), the screen appears but when I run the app after making it a startup app (Auto-run on startup option in descriptor), nothing appears on screen. I am trying the following code;
public class AppClass extends UiApplication {
public static void main(String[] args) {
AppClass theApp = new AppClass();
theApp.enterEventDispatcher();
}
public AppClass() {
pushScreen(new AppScreen());
}
}
And this is the screen class;
public final class AppScreen extends MainScreen {
private LabelField label;
public AppScreen() {
setTitle("AppTitle");
label = new LabelField();
label.setText("Ready.");
add(label);
}
}
I am expecting that its a UI app so its screen should be visible no matter if is auto-run at startup or run manually. If I need to do something to make it work as expected, please guide me about it, I am new to BlackBerry development.
I am developing in the following environment;
BlackBerry JDE Eclipse Plugin 1.5.0
BlackBerry OS 4.5
Auto start applications are run before the OS has completed booting so there isn't any support for the user interface. I suspect your application is being launched but failing on some UI call. The documented way to write an application that is to auto run and run from the home screen is to provide an alternated entry point for the auto run with arguments that tell the program it has been auto run. Then use the API to wait until the OS is ready for UI applications.
public class AppClass extends UiApplication {
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("auto-run")) {
// auto start, wait for OS
while (ApplicationManager.getApplicationManager().inStartup()) {
Thread.sleep(10000);
}
/*
** Do auto-run UI stuff here
*/
} else {
AppClass theApp = new AppClass();
theApp.enterEventDispatcher();
}
}
public AppClass() {
pushScreen(new AppScreen());
}
}
Call getApplication().requestForeground(); from the constructor of your AppScreen class so that your screen will be visible.
public final class AppScreen extends MainScreen {
private LabelField label;
public AppScreen() {
setTitle("AppTitle");
label = new LabelField();
label.setText("Ready.");
add(label);
getApplication().requestForeground();
}
}
Once the app is running in background, we have to bring it to foreground explicitly to show UI element and that is what we are doing here.

How to silence an incoming call

I am trying to silence an incoming call and prevent the BlackBerry device from ringing. I tried Alert.setVolume(0) and some EventInjector keys but this didn't work.
So how to silence an incoming call?
I was puzzled by your question and decided to take up the challenge. I tried different thing including
Playing a "silence" audio file hoping to overlap the device's ringing or occupy the media player
Hacking the phone screen via UiApplication.getUiApplication().getActiveScreen()
Injecting keyboard events
Eventually, injecting VOLUME UP key (VOLUME DOWN key works as well) event worked for me and muted the device ringing on incoming call. The drawback with this approach is that sometimes the device did ring for a fraction of second before muting.
import net.rim.blackberry.api.phone.AbstractPhoneListener;
import net.rim.blackberry.api.phone.Phone;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.EventInjector;
import net.rim.device.api.ui.Keypad;
class Muter extends AbstractPhoneListener {
public void callIncoming(int callId) {
Thread muterThread = new Thread(new Runnable() {
public void run() {
EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_VOLUME_UP, 0));
EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, (char) Keypad.KEY_VOLUME_UP, 0));
}
});
muterThread.setPriority(Thread.MAX_PRIORITY);
muterThread.start();
}
}
public class MuterApp extends Application {
public static void main(String[] args){
Phone.addPhoneListener(new Muter());
new MyApp().enterEventDispatcher();
}
}
The following also works (replace Muter thread in callIncoming() method with the following code).
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_DOWN, (char) Keypad.KEY_VOLUME_UP, 0));
EventInjector.invokeEvent(new EventInjector.KeyCodeEvent(EventInjector.KeyCodeEvent.KEY_UP, (char) Keypad.KEY_VOLUME_UP, 0));
}
});
You won't be able to disable the sound programmatically (found a couple other sources that said the same thing). The best workaround people have seemed to come up with was to use the EventInjector to change the phone's sound profile to silent.
Some Blackberry phones have a mute key. You may try the following idea:
public void callIncoming(int callId) {
if (KeyPad.hasMuteKey()) {
/* Inject KEY_SPEAKERPHONE event */
}
else {
/* Inject KEY_VOLUME_DOWN event N times, so that you get the mute effect */
}
}
i am quite new to all this...but i thought i might as well put in my 2 cents worth...
i have been trying to find ways to programatically change the profile settings...
i have found that, while we cannot(yet) change the profile settings, we can change the setting that we are using( change the profile thats in use, i think)- this is something i came across searching for info-though i should give credit to alishaik786 for the code.
public final class LoadingScreen extends MainScreen implements FieldChangeListener
{
public LoadingScreen()
{
createGUI();
}
private void createGUI()
{
try
{
ApplicationManager.getApplicationManager().launch("net_rim_bb_profiles_app");
}
catch (Exception e)
{
//Exception
}
}
public void fieldChanged(Field field, int context)
{
}
}

Resources