Windows phone 8 AdMob ReceiveAd not working - windows-phone-8

I have made unity application, and I have exported it to visual studio so I can add Google AdMob. I just want to show interstitial ad when ad loads. I am using latest Google.dll file ver:6.5.13.0. Here is my code:
//Google AdMob begin
private InterstitialAd interstitialAd;
AdRequest adRequest;
Boolean interstitialApploaded = false;
int test = 0;
//Google AdMob end
// Constructor
public MainPage()
{
var bridge = new UnityBridge();
UnityApp.SetBridge(bridge);
InitializeComponent();
bridge.Control = DrawingSurfaceBackground;
interstitialAd = new InterstitialAd("my interstitial ID");
interstitialAd.ReceivedAd += OnAdReceived;
interstitialAd.FailedToReceiveAd += OnFailedToReceiveAd;
interstitialAd.DismissingOverlay += OnDismissingOverlay;
adRequest = new AdRequest();
adRequest.ForceTesting = true;
interstitialAd.LoadAd(adRequest);
}
//Google AdMob BEGIN
private void OnDismissingOverlay(object sender, AdEventArgs e)
{
Debug.WriteLine("Ad dismissed.");
interstitialAd.LoadAd(adRequest);
}
private void OnFailedToReceiveAd(object sender, AdErrorEventArgs e)
{
Debug.WriteLine("Ad failed to load!!!!");
interstitialApploaded = false;
test = 1;
}
private void OnAdReceived(object sender, AdEventArgs e)
{
Debug.WriteLine("Ad loaded. Have fun!");
interstitialApploaded = true;
test = 2;
interstitialAd.ShowAd();
}
Now, the problem is that I am not getting any of the Debug.Writeline messages. So I guess ReceiveAd is not working.
Any thoughts?
Thank you.

Your code seems to be Right, check your internet connection and Capabilities that are needed for Ad-loading and try after removing adRequest.ForceTesting = true; that is for test Ad Interstitial.

You have to add the advertise through Unity with its advertisers there will be always an exception if you try to change the exported .sln file from Unity

Related

Accurate Windows phone 8.1 geolocation?

Im working with windows phone 8.1 geolocation. The problem that I currently have is that my code only shows the first numbers of my coordinate. Example: If the coordinate is "41.233" the app only shows "41.00" . I need it to be as accurate as possible. In case it matters, im using windows phone 8.1 emulator to try the app, not an actual phone.
My code:
public sealed partial class MainPage : Page
{
bool shouldSend = false;
DispatcherTimer timer = new DispatcherTimer();
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
private async Task GetLocation()
{
Geolocator geolocator = new Geolocator();
geolocator.DesiredAccuracy = Windows.Devices.Geolocation.PositionAccuracy.High;
try
{
Geoposition geoposition = await geolocator.GetGeopositionAsync(
maximumAge: TimeSpan.FromSeconds(1),
timeout: TimeSpan.FromSeconds(10)
);
LatitudeTxt.Text = geoposition.Coordinate.Latitude.ToString("0.00");
LongitudeTxt.Text = geoposition.Coordinate.Longitude.ToString("0.00");
LatLonTxt.Text = LatitudeTxt.Text + ", " + LongitudeTxt.Text;
var speed = geoposition.Coordinate.Speed.ToString();
ProcessingTxt.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
string result = "";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"http://proyecto-busways.rhcloud.com/colectivos?p=lta123&l=80&d=moyano&lat=" + LatitudeTxt.Text + "&lon=" + LongitudeTxt.Text + "&v=" + speed + "&Accion=Agregar");
request.ContinueTimeout = 4000;
request.Credentials = CredentialCache.DefaultNetworkCredentials;
using (HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
{
if (response.StatusCode == HttpStatusCode.OK)
{
//To obtain response body
using (Stream streamResponse = response.GetResponseStream())
{
using (StreamReader streamRead = new StreamReader(streamResponse, Encoding.UTF8))
{
result = streamRead.ReadToEnd();
}
}
}
}
}
catch (Exception ex)
{
ProcessingTxt.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
if ((uint)ex.HResult == 0x80004004)
{
// the application does not have the right capability or the location master switch is off
}
//else
{
// something else happened acquring the location
}
}
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
private async void StartSending_Click(object sender, RoutedEventArgs e)
{
await GetLocation();
timer.Tick += timer_Tick;
timer.Interval = new TimeSpan(0, 0, 5);
timer.Start();
StartSending.IsEnabled = false;
}
async void timer_Tick(object sender, object e)
{
ProcessingTxt.Visibility = Windows.UI.Xaml.Visibility.Visible;
await GetLocation();
}
private void EndSending_Click(object sender, RoutedEventArgs e)
{
timer.Tick -= timer_Tick;
timer.Stop();
StartSending.IsEnabled = true;
EndSending.IsEnabled = false;
}
private void GPS_Tapped(object sender, TappedRoutedEventArgs e)
{
Frame.Navigate(typeof(ContactPage));
}
}
Thanks for your help!
Did you try out the Geolocator.DesiredAccuracyInMeters property?
geolocator.DesiredAccuracyInMeters = 3;
Reference & Sample
In this point LatitudeTxt.Text = geoposition.Coordinate.Latitude.ToString("0.00");
LongitudeTxt.Text = geoposition.Coordinate.Longitude.ToString("0.00");
You indicated that you have 0.00 decimals, for more accuracy you should put 0.000000

How can I erase specyfic pixels of image in windows phone by finger touching the screen

I'm new to Windows Phone programming, I'm having problems, and I've been looking over the internet for the past two days and found nothing.
I'm writing and app where I've got two images one over the other, and I need to "erase" the top one by finger, a bit like using a rubber, so I can see the picture underneath. I've done drawing in general but it's not what I need right now. I found an example of something similar but it doesn't work on the phone probably because of library differences. Can anyone please help me find something that I can use? Or maybe show anything?
I found something like this, and it would be awesome if I could do something like this in windows phone 8
Note, I'm using Microsoft Visual Studio Express 2012
After few days of work, i managed to get the erasable layer.
//Created by Kamil Sokołowski on 01.11.14
//Windows Phone 7.1 Build on Microsoft Visual Studio Express 2012 for Windows Phone
public partial class MainPage : PhoneApplicationPage
{
public BitmapImage mainImage;
private WriteableBitmap writeableBitmap;
private bool isRubbing;
private SolidColorBrush brush;
private Point currentPoint;
private Point oldPoint;
private bool touchedFirst;
// Constructor
public MainPage()
{
InitializeComponent();
Canvas mainCanwas = new Canvas();
drawBackgroundLayer(new Uri("main.png", UriKind.RelativeOrAbsolute));
drawImageLayer(new Uri("para.png", UriKind.RelativeOrAbsolute));
touchedFirst = true;
}
public void drawBackgroundLayer(Uri uri)
{
BitmapImage bgi = new BitmapImage();
bgi.UriSource = uri;
BackGroundImage.Source = bgi;
}
public void drawImageLayer(Uri uri)
{
mainImage = new BitmapImage();
mainImage.UriSource = uri;
MyImage.Source = mainImage;
}
private void Tap_leftButtonDown(object sender, System.Windows.Input.MouseEventArgs e)
{
if (touchedFirst)
{
WriteableBitmap wb = new WriteableBitmap(mainImage);
Color color = new Color();
color.A = 0;
color.R = 33;
color.G = 34;
color.B = 255;
brush = new SolidColorBrush();
brush.Color = color;
touchedFirst = false;
writeableBitmap = wb;
}
isRubbing = true;
oldPoint = currentPoint;
currentPoint = e.GetPosition(MyImage);
}
private void Mouse_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
if (isRubbing)
{
oldPoint = currentPoint;
currentPoint = e.GetPosition(MyImage);
for (int i = 0; i < 40; i++)
{
for (int a = 0; a < 40; a++)
{
writeableBitmap.DrawLine((int)currentPoint.X + i, (int)currentPoint.Y + a, (int)oldPoint.X + i, (int)oldPoint.Y + a, brush.Color);
}
}
MyImage.Source = writeableBitmap;
}
}
private void ButtonLetGo(object sender, MouseButtonEventArgs e)
{
isRubbing = false;
MyImage.Source = writeableBitmap;
}
}
}
// To get this to work You need to download the WiritableBitmapEx form NuGet

Get error "InvalidRequest" when use AdMob in WP8

I'm really confusing ! I get this error randomly, Sometime the code worked (yesterday code went okay) but sometime not (today it returned "InvalidRequest" error).
I put this code in every page of my app
public MainPage()
{
InitializeComponent();
DataContext = App.MyModel;
LoadAd();
}
void LoadAd()
{
AdView av = new AdView()
{
AdUnitID = "ca-app-pub-...‏‏‏‏‏",
Format = AdFormats.Banner,
VerticalAlignment = System.Windows.VerticalAlignment.Top,
HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
};
av.FailedToReceiveAd += av_FailedToReceiveAd;
LayoutRoot.Children.Add(av);
AdRequest ar = new AdRequest();
ar.ForceTesting = true;
av.LoadAd(ar);
}
void av_FailedToReceiveAd(object sender, AdErrorEventArgs e)
{
Debug.WriteLine(e.ErrorCode.ToString());
}
I have found out that this error is mostly due to incorrect ad unit ids.
Check your adid, and make sure that its correct and doesnt have any space

Recording sound in temporary file on windows phone 8

This is my code for recording sound in temporary file. when i record sound and then listen to playback, everything goes well, but when i click again on playback button, i get this error:
How can i solve this problem?
Code:
using System.Collections.Generic;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using Coding4Fun.Toolkit.Audio;
using Coding4Fun.Toolkit.Audio.Helpers;
namespace AudioRecorder.UserControls
{
public partial class SoundRecorderPanel : UserControl
{
private MicrophoneRecorder _recorder = new MicrophoneRecorder();
private List<IsolatedStorageFileStream> _audioList = new List<IsolatedStorageFileStream>();
private int _counter;
public SoundRecorderPanel()
{
InitializeComponent();
}
private void ButtonRecord_OnChecked(object sender, RoutedEventArgs e)
{
_recorder.Start();
}
private void ButtonRecord_OnUnchecked(object sender, RoutedEventArgs e)
{
_recorder.Stop();
SaveTempAudio(_recorder.Buffer);
}
private void SaveTempAudio(MemoryStream buffer)
{
if (_counter==2)
return;
using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
{
var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
var tempFileName = "tempwaveFile_"+_counter;
IsolatedStorageFileStream audioStream = isoStore.CreateFile(tempFileName);
audioStream.Write(bytes,0,bytes.Length);
_audioList.Add(audioStream);
_counter++;
}
}
private void ButtonPlayBack_OnClick(object sender, RoutedEventArgs e)
{
var index = int.Parse(((Button) sender).Tag.ToString());
var audioPlayer = new MediaElement {AutoPlay = true};
if (index < _audioList.Count)
{
audioPlayer.SetSource(_audioList[index]);
LayoutRoot.Children.Add(audioPlayer);
audioPlayer.Play();
}
}
}
}
You can 100% use a using block. Issue was how you were attempting to access the stream in the separate event. Reopen it rather than attempt to save a reference in an index to the stream.
using (var stream = new IsolatedStorageFileStream(_fileName, FileMode.Open, storageFolder))
{
playBack.SetSource(stream);
playBack.Play();
}
Use the sample code:
https://coding4fun.codeplex.com/SourceControl/latest#source/Coding4Fun.Toolkit.Test.WindowsPhone.Common/Samples/Audio.xaml.cs
I solved my problem , it's weird but it seems using(){} does not work ! and i disposed IsolatedStorageFile and IsolatedStorageFileStream manually . and also i changed the code under ButtonPlayBack click event . this is my new code for someone who has a same problem .
private void SaveTempAudio(MemoryStream buffer)
{
if (_counter == 2)
return;
var isoStore = IsolatedStorageFile.GetUserStoreForApplication();
var bytes = buffer.GetWavAsByteArray(_recorder.SampleRate);
var tempFileName = "tempwave_" + _counter;
var audioStream = isoStore.CreateFile(tempFileName);
audioStream.Write(bytes, 0, bytes.Length);
_audioList.Add(audioStream);
_counter++;
isoStore.Dispose();
audioStream.Close();
audioStream.Dispose();
}
private void ButtonPlayBack_OnClick(object sender, RoutedEventArgs e)
{
var index = int.Parse(((Button) sender).Tag.ToString());
var fileName = "tempwave_" + ((Button) sender).Tag;
if (index >= _audioList.Count)
return;
var isoStorage = IsolatedStorageFile.GetUserStoreForApplication();
var fileStream = isoStorage.OpenFile(fileName, FileMode.Open, FileAccess.Read);
SoundPlayer.SetSource(fileStream);
SoundPlayer.Play();
isoStorage.Dispose();
fileStream.Close();
fileStream.Dispose();
}

Play sound file on Timer end

I have a countdown timer and I want an alarm to go off when it reaches the end ... lots for Android and iOS, but nothing that I could find for WP8.
I'm using the DispatcherTimer for counting down.
I'm looking for some information or an example on how to call a sound when the timer finishes counting down. I have the counter start on a button click and reset on a long press. It all works good, just want a sound effect when it stops after counting down.
private DateTime EndTime { get; set; }
private DispatcherTimer _dispatcherTimer;
private void BtnCounter_Click(object sender, RoutedEventArgs e)
{
if (this._dispatcherTimer == null)
{
this._dispatcherTimer = new DispatcherTimer();
this._dispatcherTimer.Interval = TimeSpan.FromMilliseconds(100);
this._dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
}
if (this.EndTime == DateTime.MinValue)
{
this.EndTime = DateTime.Now + (TimeSpan)this.tsPicker.Value;
}
this._dispatcherTimer.Start();
}
void dispatcherTimer_Tick(object sender, EventArgs e)
{
var remaining = this.EndTime - DateTime.Now;
int remainingSeconds = (int)remaining.TotalSeconds;
this.tsPicker.Value = TimeSpan.FromSeconds(remainingSeconds);
if (remaining.TotalSeconds <= 0)
{
this._dispatcherTimer.Stop();
// Sound code should go here, or a method call to it.
}
}
private void BtnCounter_Hold(object sender, System.Windows.Input.GestureEventArgs e)
{
cnt = 0;
BtnCounter.Content = cnt;
this._dispatcherTimer.Stop();
this.EndTime = DateTime.MinValue;
this.tsPicker.Value = TimeSpan.FromSeconds(0);
}
protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
{
this.EndTime = DateTime.MinValue;
base.OnNavigatedFrom(e);
}
Have you tried using a MediaElement? There seems to be a good example using it, titled Windows Phone 8: Playing Sounds