Favour foreground app not working for HCE payments Android - nfc

I'm facing a strange issue in my HCE payments. I have two payments application in my mobile. One was developed by me and other is Android pay. In Tap&Pay the default one is "Android Pay" and my app is non-default and enabled "Favour foreground app".
Now my problem is when I try to make payments (Tap device to POS), the device always prompting "Android Pay" instead of my app.
I followed all guidelines given in Android documentation.
Android HCE guide
Do I need to enable anything in my code to make this happen?

In order to leverage the "Favor Foreground App" preference, you need to tell CardEmulation that your app is ready to intercept the terminal tap. By default, your app won't intercept the tap.
In our app, I do this in onPause() and onResume() in each Activity (or you can extend a common Activity and just do this once.
in onResume() call
public boolean setPreferredService (Activity activity, ComponentName service)
in onPause(), call
public boolean unsetPreferredService (Activity activity)

Related

Hide app UI after starting Foreground Service

I'm developing an Android app with Xamarin (tried Maui and Xamarin.Forms but can't figure out this problem so now trying Xamarin.Android but still struggling). So far I've discovered that my app should invoke a "foreground service", as it needs to constantly monitor the accelerometer. This I can do.
The bit I'm struggling with now is, after invoking the foreground service, how to completely hide the app UI so the foreground service continues to run in the "background"?
Customize a Service and override the method OnStartCommand , use StartForeground method to register Foreground Service, here you need to create a notification to display what you want to monitor.
var notification = new Notification.Builder(this)
.SetContentTitle(Resources.GetString(Resource.String.app_name))
.SetContentText(Resources.GetString(Resource.String.notification_text))
.SetSmallIcon(Resource.Drawable.ic_stat_name)
.SetContentIntent(BuildIntentToShowMainActivity())
.SetOngoing(true)
.AddAction(BuildRestartTimerAction())
.AddAction(BuildStopServiceAction())
.Build();
// Enlist this instance of the service as a foreground service
StartForeground(Constants.SERVICE_RUNNING_NOTIFICATION_ID, notification);
Use StartForegroundService instead of StartService with the service intent(On Android 8.0 and higher ).
Docs : https://learn.microsoft.com/en-us/xamarin/android/app-fundamentals/services/foreground-services
Sample : https://learn.microsoft.com/en-us/samples/xamarin/monodroid-samples/applicationfundamentals-servicesamples-foregroundservicedemo/

Xamarin - White screen on ComposeEmail

Using a physical android device.
When ComposeEmail is called, the email client opens.
Once the email client opens, the app goes to white screen.
If I go back to the app it will stay on white screen.
If I hit the back button I will be brought to the login screen.
Does there need to be some session management here if an external app opens?
public async void SendEmail(EmailMessage message) {
await Xamarin.Essentials.Email.ComposeAsync(message);
}
According to your description, you want to solve the problem of the white screen of the application. You can implement the operation you want in the OnResume method in the App.xaml.cs class, OnResume will be called when the app goes from the background to the app interface.
In Xamarin, the official support for using Email is provided. You can use Xamarin.Essentials: Email, and it will not show a white screen interface.Information about using Xamarin.Essentials: Email can be found at :Xamarin.Essentials: Email.

Android Watch/Phone MessageApi

I am working on an app for Android Watch that requires the mobile app to be on or in background. I tried using the MessageApi in order to communicate with the app on the phone, but even if the app is not on, i get a message back like it is on.
What would you suggest to check whether the phone app is running (doesnt matter whether it is foreground/background) before i enable the activity on the Android Watch?
Thanks for the help.
If you have registered a WearableListenerService in your mobile app, that will be invoked by the framework even if your app is not running (and will be invoked if your app is running, too). If, however, you are not using that service, then to receive messages or notification on changes in the wear network in your mobile app, you would need to register one or more callback listeners for the type of messages/data that you are interested in. In that case, that means if your app is not running, you will not be getting those callbacks on your mobile app. To use this, however, be sure to manage the lifecycle of your listeners in your mobile app according to your needs. For example, one can register for such listeners in onResume() of an activity and unregister in onPause(). The consequence of that is if your activity loses focus (but still alive), that activity will not receive the callback (even though as an instance it is still running). You may want to define an Application instance for your app and use that to listen for callbacks but, again, it depends on the exact nature of your needs and app.
You can search for nodes and parse them for needed result, or to check if you have a nearBy node
private Collection<String> getNodes() {
HashSet <String>results = new HashSet<String>();
NodeApi.GetConnectedNodesResult nodes =
Wearable.NodeApi.getConnectedNodes(mGoogleApiClient).await();
for (Node node : nodes.getNodes()) {
results.add(node.getId());
}
return results;
}

Windows phone SMS plugin with extra functions

I'm using the code from this article, with phonegap app.
http://blogs.msdn.com/b/glengordon/archive/2011/12/02/phonegap-on-wp7-tip-3-sending-sms-and-intro-to-plugins.aspx
The plugin works all fine, but when the SMS is sent, I want to return to my app automatically. Is this possible? If its possible to send an SMS without go to the default integrated sender, it could be even better.
I'm a newbie to C# and windows phone apps - please help me ;)
there is no way to avoid the integrated SMS sender due to security reasons. User will return to your app after hitting the Back button on the SMS conversation page (that is esured automatically because of the stack-controlled nature of paging in WP7, but will not return after hitting the home button (again, this behavior cannot be prevented in any way) and your app will be suspended (possible to return to it by holding the back button and choosing it).

Unsuscribe to WP7 notification for uninstalled application

I have a toast notification system that is working on WP7. When I send a notification, all registered devices receive the toast notification.
But, If someone uninstall the application, I will continue to try to send to the registered device (in fact, I will ask Microsoft service to send to the unavailable device).
Is it possible to detect if someone uninstall the app, then I can remove it from my list of device to send.
Or maybe can Ms services tell me if the app as unsuscribe to the toast notification ?
My list of registered device grows infinitely ....
Thanks in advance for any Help,
Best regards
You can't detect if the user deleted the app, but can always check the subscription status return code when you send a notification!
Check here for the return codes, specifically where the SubscriptionStatus != Active

Resources