Add contact in WP7 without using show() method - windows-phone-7

I wish to add new contacts in WP7. I have used the following
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
SavePhoneNumberTask savePhoneNumber = new SavePhoneNumberTask();
code.savePhoneNumber.Completed += new EventHandler<TaskEventArgs>(savePhoneNumber_Completed);
savePhoneNumber.PhoneNumber = "1987654320";
savePhoneNumber.Show();
}
This shows add more details of Contact page, if we press save then only it is saved.
But i want to save the contacts without calling Show() method.
Please anyone help me.....

You can't and you shouldn't be able to.
Imagine that we could add contacts silently. Apps would start spamming my contacts.
This is the way it works.

Related

A Particular page must be opened when he user uses the windows app for the first time

I am developing a windows 7 phone app where I want a particular page( A privacy policy which the user needs to accept ) to be displayed when the user uses the app for the first time in his phone. Can any one please tell me how to get this done.
Two approaches can be taken for this functionality. The first is to always start at the privacy policy page but override the OnNavigatedTo method to check if the policy has been accepted before. If it has, navigate to your "MainPage". Within the Mainpage, remove all backstack entries.
Privacy Policy Page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// have the accepted the policy?
var settings = IsolatedStorageSettings.ApplicationSettings;
bool accepted;
if(settings.TryGetValue("PolicyAccepted", out accepted))
{
if (accepted)
{
NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}
}
}
private void OnAcceptButtonClick(object sender, RoutedEventArgs routedEventArgs)
{
var settings = IsolatedStorageSettings.ApplicationSettings;
settings["PolicyAccepted"] = true;
settings.Save();
NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}
Then in your MainPage, remove the backstack
protected override void OnNavigatedTo(NavigationEventArgs e)
{
while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry();
}
The second approach is to is a UriMapper as described in this SO answer.
A possible answer to this question can be found here. As you want your page to open up only once I suggest IsolatedStorageSettings to save a boolean value if the user has accepted the policy or not.

Facebook authentication shows deprecated method error

I'm using the Facebook C# SDK and trying to authenticate my user. The first part sort of worked, my app showed me the facebook login page inside a browser control.
This is the code I have, I was following this example.
private readonly FacebookClient _fb = new FacebookClient();
private void Browser_Loaded(object sender, RoutedEventArgs e)
{
var loginUrl = GetFacebookLoginUrl();
BrowserControl.Navigate(loginUrl);
}
private Uri GetFacebookLoginUrl()
{
var parameters = new Dictionary<string, object>();
parameters["client_id"] = FacebookSettings.AppID;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "page";
if (!string.IsNullOrEmpty(FacebookSettings.ExtendedPermissions))
parameters["scope"] = FacebookSettings.ExtendedPermissions;
return _fb.GetLoginUrl(parameters);
}
After I filled in my details to log into facebook, I got this error:
Any idea's which method is deprecated and how I can fix this?
I used the same code and it's working. And such an error is occuring because of a bug in the facebook API, when display parameter is set to "touch" or "wap". That shouldn't occur when using "page". Try using "popup" as the display.
Try changing the july 2012 Breaking Changes in the app's advanced settings tab(in developer.facebook.com). Refer to this link for information on this issue. And similar issue in facebook developer site.

Get response from web browser for windows phone 'mango'

I m my application I want to use Webbrowser which will be using Wifi,after the Webbrower opens the the link (task.URL) ,I want to check what is the response like whether the linked got opened or it failed.How do I do that means get the response ?
WebBrowserTask task = new WebBrowserTask();
task.URL = "https://www.goggle.com/";
task.Show();
kindly help
Thanks.
Usually, to catch this use NavigationFailed event as follow:
void WebPage_Loaded(object sender, RoutedEventArgs e)
{
this.webHome.Navigate(new Uri(www,UriKind.Absolute));
this.webHome.NavigationFailed += webHome_NavigationFailed;
}
void webHome_NavigationFailed(object sender, System.Windows.Navigation.NavigationFailedEventArgs e)
{
this.webHome.NavigateToString("No web page available.");
}

Using webclient with htmlAgilityPack on wp7 to get html generated from javascript

i want to get the time schedule on
http://www.21cineplex.com/playnow/sherlock-holmes-a-game-of-shadows,2709.htm
first,
i have tried using webclient with htmlAgilityPack and get to the table id = "table-theater" but appearently the html generated from java script so the table innetHTML is empty.
public void LoadMovieShowTime(string MovieLink)
{
WebClient MovieShowTimeclient = new WebClient();
MovieShowTimeclient.DownloadStringAsync(new Uri(MovieLink));
MovieShowTimeclient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(MovieShowTimeclient_DownloadStringCompleted);
}
void MovieShowTimeclient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(e.Result);
var node = doc.DocumentNode.Descendants("div").First()
.Elements("div").Skip(1).First()
.Elements("div").Skip(1).First()
.Element("div")
.Elements("table").FirstOrDefault(table => table.Attributes["class"].Value == "table-theater");
}
Is it possible to get the data using webclient on windows phone? or is there any pssible way to get it using another method?
second,
i have tried to get the time schedule from mobile site which is
http://m.21cineplex.com/gui.list_schedule?sid=&movie_id=11SHGO&find_by=1&order=1
but the return ask me to enable cookies. im new to this, i find that there is a way to extend webclien ability by overriding the webRequest cookies, but cant find any reference how to use it.
thanks, for any reply and help :)
Just because the table is generated in JavaScript does not mean the WebBrowser control will not render it. Ensure that IsScriptEnabled is set to true, this will ensure that the JavaScript that renders the table is executed. You can then 'scrape' the results.

MediaElement Windows Phone 7

I'm creating a little app to help me better understand how to play sounds on WP7 devices but I'm having a problem actually getting the sound to come out of the device.
I have the following code:
<MediaElement x:Name="note1" Source="test.mp3" AutoPlay="False" />
private void btn1_Click(object sender, RoutedEventArgs e)
{
note1.Source = new Uri("test.mp3", UriKind.Relative);
note1.Play();
}
Where test.mp3's Build Action is a Resource.
The thing I don't understand is when I add a breakpoint on the method btn1_Click and I stop at note1.Play() it actually plays test.mp3 but when debug without breakpoints and click on the button I hear nothing.
Is there a way to fix this issue?
Have you tried playing with test.mp3's Build Action set as content.
Also did you close zune software after it recognizes the phone and completes sync, and connect using wp7connect tool. for more info about wp7connect tool try here.
zune locks all media on wp7 device and you cant play any media, but the status of the media will be "ended".
try setting up media's following events MediaFailed MediaOpened,MediaEnded, DownloadProgressChanged, CurrentStateChanged and BufferingProgressChanged
Also, make sure you have add the capability ID_CAP_MEDIALIB to your manifest (WMAppManifest.xml), this seems to be required for MediaElement (otherwise you'll get AG_E_NETWORK_ERROR in your MediaFailed handler).
i dont recommend mediaElement for more than one audio item ..it has weird effects ...use something like:
Stream stream = TitleContainer.OpenStream(#"Audio/buzzer.wav");
SoundEffect effect = SoundEffect.FromStream(stream);
FrameworkDispatcher.Update();
effect.Play();
using the xna framework ....and make sure there WAV files.
Uri kind must be RelativeOrAbsolute.
private void btn1_Click(object sender, RoutedEventArgs e)
{
note1.Source = new Uri("test.mp3", UriKind.RelativeOrAbsolute);
note1.Play();
}
You need to make sure the MediaElement has been opened before you can call .Play() on it - you can do so by adding an event receiver to the MediaOpened event. It would also be good to call .Stop() any time prior to reassigning the Source property - take a look at this thread for more details.
This can't be solved without an Eventhandler. Do as mentioned below.
<MediaElement x:Name="note1" Source="test.mp3" AutoPlay="False" />
private void btn1_Click(object sender, RoutedEventArgs e)
{
note1.Source = new Uri("test.mp3", UriKind.Relative);
note1.MediaOpened += new RoutedEventHandler(note1_MediaOpened);
}
void note1_MediaOpened(object sender, RoutedEventArgs e)
{
note1.Play();
}
this is perfectly works. enjoy...

Resources