Xamarin.forms make phone call without going to dialer in Android - xamarin

In my Xamarin.forms app, I can call a specified phone number using Xamarin.Essential plugin. The problem I am facing is, when I click to call on my app in Android it will open the phone dialer and the user should manually click call.
In iOS, it will directly place a call without going to the dialer. What my intention is to prevent editing of the number in the dialer.
So, How can I call the number without going into dialer instead it should show calling screen directly in android? I have seen many posts, but I didn't get any ideas. Any help is appreciated.
I am making a call using xamarin.Essential plugin like this
PhoneDialer.Open(PhoneNumber.Text);

To place a phone call directly, you can use Xam.Plugins.Messaging library:
After installing the nuget, add this line in Android project MainActivity's OnCreate method:
CrossMessaging.Current.Settings().Phone.AutoDial = true;
Now you can place any call directly like below:
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall)
phoneDialer.MakePhoneCall("+27219333000");
Please note using this settings requires the
android.permission.CALL_PHONE added to the manifest file.

Related

Deep linking and shortcuts in Genexus (android)

I have a question about deep linking in genexus.
I have a site that calls a url. This url should be handled by an app installed on your phone. The procedure works correctly using the deep link.
The problem arises if the starting site is opened from a shortcut placed on the desktop. In this case the deep link of the app no ​​longer works.
I think the problem is related to this
Deep link in android app
and that the shortcut counts as an android app thus preventing me from calling another app.
But in the past this link worked as long as the app was told beforehand to always handle the link.
Is there anything I can do in Genexus to use the deep link even starting from a desktop shortcut?
The DeepLink external object helps you manually manage deep linking on your applications. This external object must be used only in the Smart Devices Main object.
Suppose that our website handles URIs such https://www.mystore.com/viewproduct?1
Event DeepLink.Handle( &URL, &IsHandled )
Composite
if &URL.ToLower().StartsWith("https://www.mystore.com/")
and &URL.Contains("viewproduct")
&Index = &URL.indexof( "?" )+1
&Query = &URL.Substring( &Index)
&ProductId = &Query.Trim().ToNumeric()
&IsHandled = True
SDViewProduct(&ProductId)
endIf
EndComposite
EndEvent
For more details: DeepLink external object

Call c# function from javascript in Xamarin.Forms Webview

I want to make call of some c# code when user tap on a button in html. I followed below example and also tried it and it is working for my purpose if i use it as it is.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/custom-renderer/hybridwebview
It uses index.html from assets, instead i want to use some URL where my html page is. But unfortunately when i change url, it stops invoking c# code.
Please let me know if there are any changes needed to get it working.
It was some firewall settings blocking communication from my iOS simulator, got it fix after adding certificate.
Example demo is working fine now

Navigating from xamarin multi-platform page to iOS or android page

I'm trying to follow this tutorial on creating a login page using Auth0: https://auth0.com/docs/quickstart/native/xamarin/01-login#handing-the-callback-url and noticed that the tutorial creates two separate login pages for android and iOS, as if they are two separate apps/projects/solutions. But my app is supposed to be compatible with both android and iOS, so I created a forms page under RoseySports.ios called Login_iOS (As indicated in screenshot 1) and would like to test it out to see if the login page works, but cannot seem to find a way to set the MainPage as Login_iOS (screenshot 2). I would like for it to be so that if a device is running iOS, it will redirect the user to the iOS version of the login page, and vice versa for android. Sorry if I'm not using the correct terminology when describing my issue. The reason I had to create two separate login pages for iOS and android was because i had to use using Auth0.OidcClient; as there are separate Nuget packages for the iOS solution and Android solution, which doesn't work when trying to put it on the main project (the one compatible for both iOS and Android).
And please let me know if there's a way to make just one login page for both platforms using Auth0.
UPDATE:
This is what I've done now, but I'm getting an error at MainPage = new RoseySports.Login_iOS(); saying that Login.iOS does not exist in the namespace RoseySports. This is the rest of the code:
`switch(Device.RuntimePlatform)
{
case Device.iOS:
MainPage = new RoseySports.Login_iOS();
break;
case Device.Android:
MainPage = new Login_Page();
break;
}`
You have multiple questions and in StackOverflow you should not ask them in one question, but let's try to address them:
Pages are only graphic elements and there is no need to implement separate graphic elements in iOS and Android in most cases, and yours doesn't look like a valid one for that
In general you can implement some code as platform specific. If you are using shared projects you can use conditional compiling, if not then dependency injection
You can use some of the technics above to do what you wanted to do (have different versions of pages per platform)

How can I create a method to detect when a notification is clicked using xamarin coss-platform portable?

I´m a bit new to Xamarin Forms development, but not to Android (Java) development. Here´s the scenario:
I´ve developed an app for android, which schedules notifications (NotificationManager) and adds an intent to each notification in order to redirect the user to a specific url inside a webview. The url came from the notification intent.
So, I´m doing exactly the same thing in xamarin, in order to build the iOS version. Since I´m also an ASP.NET, I chose this method.
I´ve done all the basic stuff, so far:
created the webview with the right address;
created the routine which sets the cross-platform notifications using CrossLocalNotifications (Xam.Plugins.Notifier)
This is the problem:
I need to create a method in which the app redirects (webview) the user, once he clicks the notifications, in the portable solution level. I think I can manage to develop the logic to use the webview I currently have. I just can´t seem to find anywhere on the web a tip for creating a method to "listen" to the user click and catch information (or just the ID) of the notification created, so I can build the routine.
Anyone can help or have a better solution?

Force a call in WP7

I wonder if it was possible to force a call without using the messagebox confirmation (in debug mode for example...)?
I use currently PhoneCallTask ​​to make a call.
(My application should never go on the market place)
Thank you for your answers,
There is no other way to make a call then using PhoneCallTask(), even if your app is not going on the marketplace.
The current Windows Phone SDK only provides the PhoneCallTask to make calls, and this class shows the confirmation message box, so the answer is no...

Resources