I need to develop an app to make a call from the Windows Phone 8 app using Visual Studio.
But I couldn't find any resources to do it.
When a button is clicked I need to call to a mobile number which is already given.
By clicking that button I must call only to that mobile number.
This is what I coded. When a given button is clicked, I this method is calling...
private void HyperlinkButton_Click_1(object sender, RoutedEventArgs e)
{
PhoneCallTask phoneCallTask = new PhoneCallTask();
phoneCallTask.PhoneNumber = "0719957868";
phoneCallTask.DisplayName = "Gage";
phoneCallTask.Show();
}
But I get an unhandled exception.
Unhandled exception.
// Code to execute on Unhandled Exceptions
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
if (Debugger.IsAttached)
{
// An unhandled exception has occurred; break into the debugger
Debugger.Break();
}
}
When you use PhoneCallTask, you have to specify a new Capability of your app in WMAppManifest.xaml: ID_CAP_PHONEDIALER
source
This is how you should do it:
PhoneCallTask phoneCallTask = new PhoneCallTask();
phoneCallTask.PhoneNumber = "2065550123";
phoneCallTask.DisplayName = "Gage";
phoneCallTask.Show();
Remember that the call is not automatically started but it prompts the user to confirm that action.
Here is how to initiate a call on windows phone
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh394025(v=vs.105).aspx
Ok for future reference i must add this.
If you get an Unauthorized Access Exception then you need to enable ID_CAP_PHONEDAILER from the Capabilities section in the WMAppManifest.xml file.
See here
Related
I am expermenting with video recording on Windows Phone 8. I want to handle the situation when user is putting my app to background, while it is recording a video. I would like to save the already recorded video before quitting.
I am handling this situation using the code from this example:
https://msdn.microsoft.com/en-us/library/windows/apps/mt243896.aspx
private async Task StopRecordingAsync()
{
try
{
Debug.WriteLine("Stopping recording...");
_isRecording = false;
await _mediaCapture.StopRecordAsync();
Debug.WriteLine("Stopped recording!");
}
catch (Exception ex)
{
Debug.WriteLine("Exception when stopping video recording: {0}", ex.ToString());
}
}
I am calling this method from the:
protected async override void OnNavigatingFrom(NavigatingCancelEventArgs e)
But the video is not being saved. In the debug console I get only the first message: "Stopping recording...", but there is no "Stopped recording!" message logged. It seems like the resources are being destroyed before I can handle them.
When your app is moved to the background you only have a short amount of time to run code.
Instead of having saving be triggered when you navigate from the page, instead look at the Application.Suspending event which allows you to use a deferral to try and run your code for a bit longer so you can finish tidying up before your app loses it's resource allocation.
Something like:
async protected void OnSuspending(object sender, SuspendingEventArgs args)
{
SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral();
await StopRecordingAsync();
deferral.Complete();
}
I used this method (from msdn) to extend splashscreen in my app but while navigating after showing extended splash screen it is throwing error.
Error:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
Code:
void DismissedEventHandler(SplashScreen sender, object e)
{
dismissed = true;
/*
Here I will load data from web
*/
//Here i am unable to navigate on MainPage
rootFrame.Navigate(typeof(MainPage), LoadedData);
Window.Current.Content = rootFrame;
}
If you need more code then its same as of above mention link.
So how can navigate to MainPage?
You can dispatch the navigation to run on the UI thread with Dispatcher.RunAsync https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.coredispatcher.runasync.aspx
I am trying to integrate an interstitial AdMob ad into a Windows Phone 8 MonoGame. It is the newest version of MonoGame (3.2) and the newest version of the AdMob SDK for Windows Phone 8 (6.5.13). Ideally I would like to be able to preload the ad and show it when the player dies.
This first example works, but it calls ShowAd directly in the event handler when the ad was received.
public void LoadAndShowAd()
{
interstitial = new InterstitialAd("xxx");
interstitial.ReceivedAd += OnAdReceived;
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitial.LoadAd(adRequest);
}
private void OnAdReceived(object sender, AdEventArgs e)
{
interstitial.ShowAd();
}
This slightly modified example does not work. The ad is received and is ready, but the call to ShowAd crashes within the GoogleAds.DLL with a NullReferenceException. As you can see the only difference is that ShowLoadedAd is called at a later point in time when the ad is ready.
public void LoadAd()
{
interstitial = new InterstitialAd("xxx");
interstitial.ReceivedAd += OnAdReceived;
AdRequest adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitial.LoadAd(adRequest);
}
public void ShowLoadedAd()
{
if (isReady)
interstitial.ShowAd();
}
private void OnAdReceived(object sender, AdEventArgs e)
{
isReady = true;
}
The "interstitial" object itself is not null, the exception happens within the GoogleAds dll as shown in the stack trace below. The exception itself sadly does not give away much:
System.NullReferenceException was unhandled by user code HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=GoogleAds
StackTrace:
at A.c81d6e02e9732689b8a214cc526c72649.c8b6f578dd247fa29b178e585ca8da582()
at A.c81d6e02e9732689b8a214cc526c72649.ce00282f6ceb6d2b777527815c84e2081()
at GoogleAds.InterstitialAd.ShowAd()
at GameName10.GamePage.<Test2>b__1()
InnerException:
The Google Ads example for Windows Phone 8 and interstitial ads actually uses the second approach which causes the exception in my monogame project. So I assumed it could be an issue with these calls being made from the game loop of monogame being in a different thread. I wrapped all the calls to these functions in Dispatcher.BeginInvoke calls to make sure they are called on the UI thread. However this does not change anything, the first example works regardless if it is wrapped in BeginInvoke or not and the second one does not.
Any input in how to solve this issue or integrate an interstitial AdMob ad into MonoGame successfully is appreciated.
Thanks
Windows phone 8.1 new to world. Basic function is back button click. Is that function not working properly is this windows phone 8.1. Is that behavior or i'm made mistake.
Below code using in Homepage but this code calling from all other class too while clicking back. I need to access below method only on Home page .
Please check below code and refer me good solution.
Please look my code:
public HomePage()
{
this.InitializeComponent();
Windows.Phone.UI.Input.HardwareButtons.BackPressed += HardwareButtons_BackPressed;
}
void HardwareButtons_BackPressed(object sender, BackPressedEventArgs e)
{
}
Thanks
It is working properly. The BackPressed event is working app-wide. Two options that come to my mind:
write eventhandler that would recognize the Page in which you currently invoke it - simple example can look like this:
private void HardwareButtons_BackPressed(object sender, Windows.Phone.UI.Input.BackPressedEventArgs e)
{
Frame frame = Window.Current.Content as Frame;
if (frame == null) return;
if (frame.Content is HomePage)
{
e.Handled = true;
Debug.WriteLine("I'm in HomePage");
}
else if (frame.CanGoBack)
{
frame.GoBack();
e.Handled = true;
}
}
second option - subscribe to Windows.Phone.UI.Input.HardwareButtons.BackPressed when you enter the Page and unsubscribe when you leave the Page. Note that in this way there are some pitfalls - you have to handle properly OnNavigatedTo, OnNavigatedFrom, Suspending and Resuming (more about Lifecycle here). Note also that the subscription should be done before others - for example NavigationHelper.
Some remarks - the above code should work, but it also depends on other circumstances:
if there is something other subscribed to BackPressed before (in App.xaml.cs) - remember that usually events are fired in order they were subscribed
check if you are using NavigationHelper - it also subscribes to BackPressed
remember not to subscribe multiple times
remember to allow the User to leave your HomePage
I'm trying to use the C++ Accelerometer interface in the Windows::Devices::Sensors namespace on the Windows Phone 8. The code is very similar to a C# project I have that works, but I can't get the C++ event to fire like I can with my C# code.
My C++ code is a C# project with a C++ component, the C++ component just opens up the Accelerometer device for reading, and then tries to setup an event to fire whenever data is ready:
AccelerometerWrapper::AccelerometerWrapper() {
Accelerometer^ acc = Accelerometer::GetDefault();
accReading = acc->ReadingChanged::add( ref new TypedEventHandler<Accelerometer^, AccelerometerReadingChangedEventArgs^>(this, &AccelerometerWrapper::ReadingChanged));
}
void AccelerometerWrapper::ReadingChanged(Accelerometer^ sender, AccelerometerReadingChangedEventArgs^ e) {
...
}
Unfortunately, my ReadingChanged() function is never being called. I've looked around for a Start() method or somesuch but I can't find anything. I'm basing most of my knowledge off of the AccelerometerCPP example, but I can't actually test that as it is a generic WinRT (e.g. Windows 8, not Windows Phone 8) example, and my computer does not have an accelerometer. Everything compiles and runs, the event is just never triggered.
EDIT: I have successfully run a test to verify that I can manually call acc->GetCurrentReading(), so the accelerometer is working, it just seems to be the event that is not getting triggered.
Thank you in advance!
I'm not a C++ expert, but the new Accelerometer sensor works on my machine using C#.
private void MainPage_Loaded(object sender, RoutedEventArgs e)
{
var accelerometer = Accelerometer.GetDefault();
if (accelerometer != null)
{
accelerometer.ReadingChanged += accelerometer_ReadingChanged;
}
}
void accelerometer_ReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs args)
{
Debug.WriteLine(args.Reading.AccelerationX + ", " + args.Reading.AccelerationY + "," + args.Reading.AccelerationZ);
}
When we run that code snippet we can see the following expected output:
Just a guess for C++, do you need to cache the Accelerometer instance somewhere instead of letting it go out of scope?