Google WindowsPhone Store 8.1 vs WindowsPhone 8: Launchers and Choosers(C#-XAML) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Thursday, 1 May 2014

WindowsPhone Store 8.1 vs WindowsPhone 8: Launchers and Choosers(C#-XAML)

Introduction

Windows Phone store 8.1 introduces an important change in the Windows Phone developer ecosystem. In this release, Windows Phone converges with the Windows Store apps platform into a single developer platform that runs the same types of apps i.e Windows Runtime apps.There is lot of changes included between windowsphone 8.0 and windowsphone store 8.1 .Like windowsPhone 8.0 there is no Launchers and Choosers  available  in  windowsphone store 8.1 ,as well as namespace "Microsoft.Phone.Tasks" is no longer available in store 8.1 OS.

However in this post ,i am going to explain about what are the alternative ways for launching in-built apps in windowsPhone Store 8.1 for following realtime major functionalitie's .

Building the Sample

  • Make sure you’ve downloaded and installed the Windows Phone SDK. For more information, see Get the SDK.
  • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
  • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows.
  • Downloaded sample is targeted on WindowsPhone Store 8.1 Universal APPS.
You should add following cababilities in "Package.appxmanifest" file
  1. Contacts(Permission for getting phone contacts).
  2. Microphone,Webcam(for camera caprture)
  3. Pictures Library(For pick photo from gallery)

Desription

1)WindowsPhone  8.0 Launchers and choosers:

I am really sorry ,In this post i want to focus on windows phone store 8.1 sample,So please read  to understand WindowsPhone 8.0 launchers and choosers.Because there is lot resources avaialable for understand this category.

2)WindowsPhone Store 8.1 Launchers and choosers:

To make common UI framework with windows Runtime APIs,like WindowsPhone 8.0 there is no Launchers and Choosers available in WindowsPhone store 8.1 .Because of namespace "Microsoft.Phone.Tasks" namespace is no longer available in new store 8.1 0S.Ok lets start for alternative ways.
2.1)How to compose new sms message in windowsphone store 8.1:
We can launch SMS dialog to allow the user send an SMS. You can pre-populate the fields of the SMS with data before showing the dialog. Like wp8.0  message will not be sent until the user taps the send button.
Step1:
Create a new ChatMessage object 
C#
var chatMessage = new Windows.ApplicationModel.Chat.ChatMessage();
Step2:

 Set the data that you want to be pre-populated in the compose email dialog. 
C#
chatMessage.Body = "messageBody"; 
chatMessage.Recipients.Add("1234567891");
Step3:  

  Call ShowComposeSmsMessageAsync to show the dialog.
C#
await Windows.ApplicationModel.Chat.ChatMessageManager.ShowComposeSmsMessageAsync(chatMessage);
  Note: ChatMessage is not supported in windows store
2.2)How to compose new email in windowsphone store 8.1:
We can launch Email dialog to allow the user send an Email. You can pre-populate the fields of the Email with data before showing the dialog. Like wp8.0  message will not be sent until the user taps the send button.
Note:If you are not added your gmail account to device,you may prompt like
To add your Gmail account to phone,go to Settings=>email+accounts=>add an account=>Google
C#
private void EmailCompose_Click(object sender, RoutedEventArgs e) 
  { 
       ComposeEmail(); 
  }
C#
 private async void ComposeEmail() 
        { 
            var contactPicker = new Windows.ApplicationModel.Contacts.ContactPicker(); 
            contactPicker.DesiredFieldsWithContactFieldType.Add(ContactFieldType.Email); 
            Contact recipient = await contactPicker.PickContactAsync(); 
            if (recipient != null) 
            { 
                this.AppendContactFieldValues(recipient.Emails); 
                 
            } 
            else 
            { 
                OutputTextBlock.Text = "No recipient emailid Contact found"; 
            } 
 
        }
C#
private async void AppendContactFieldValues<T>(IList<T> fields) 
        { 
            if (fields.Count > 0) 
            { 
                 
                if (fields[0].GetType() == typeof(ContactEmail)) 
                { 
                    foreach (ContactEmail email in fields as IList<ContactEmail>) 
                    { 
                        var emailMessage = new Windows.ApplicationModel.Email.EmailMessage(); 
                        emailMessage.Body = "choosers sample"; 
                        emailMessage.Subject = "SubramanyamRaju WindowsPhone Tutorials"; 
                        var emailRecipient = new Windows.ApplicationModel.Email.EmailRecipient(email.Address); 
                        emailMessage.To.Add(emailRecipient); 
                        await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage); 
                        break; 
                    } 
                } 
                
            } 
            else 
            { 
                OutputTextBlock.Text = "No recipient emailid Contact found"; 
            } 
        }
 Note: EmailMessage is supported in windows store 

2.3)How to make phone call  in windowsphone store 8.1:


We can launch the built-in phone call UI.Like wp8.0  message will not be sent until the user taps the call button.
 
C#
 string number = "1234567890"; 
 string name = "subbu"; 
 PhoneCallManager. ShowPhoneCallUI (number, name);

Note: PhoneCallManager is not supported in windows store.
  
2.4)How to capture photo using camera in windowsphone store 8.1:
The MediaCapture class is used to capture audio, video, and images from a camera. The InitializeAsyncmethod, which initializes the capture device, must be called before you can start capturing from the device.

C#
Windows.Media.Capture.MediaCapture captureManager; 
 
async private void InitCamera_Click(object sender, RoutedEventArgs e) 
{ 
    captureManager = new MediaCapture(); 
    await captureManager.InitializeAsync(); 
} 
 
async private void StartCapturePreview_Click(object sender, RoutedEventArgs e) 
{ 
    capturePreview.Source = captureManager; 
    await captureManager.StartPreviewAsync(); 
} 
 
async private void StopCapturePreview_Click(object sender, RoutedEventArgs e) 
{ 
    await captureManager.StopPreviewAsync(); 
} 
 
async private void CapturePhoto_Click(object sender, RoutedEventArgs e) 
{ 
    ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg(); 
 
    // create storage file in local app storage 
    StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync( 
        "TestPhoto.jpg", 
        CreationCollisionOption.GenerateUniqueName); 
 
    // take photo 
    await captureManager.CapturePhotoToStorageFileAsync(imgFormat, file); 
 
    // Get photo as a BitmapImage 
    BitmapImage bmpImage = new BitmapImage(new Uri(file.Path)); 
 
    // imagePreivew is a <Image> object defined in XAML 
    imagePreivew.Source = bmpImage; 
} 
2.5)How to select/pick photo from gallery in windowsphone store 8.1:
FileOpenPicker is used to pick a file based on FileTypeFilter.To pick photo from galley do like this 
C#
 FileOpenPicker openPicker = new FileOpenPicker(); 
            openPicker.ViewMode = PickerViewMode.Thumbnail; 
            openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary; 
            openPicker.FileTypeFilter.Add(".jpg"); 
            openPicker.FileTypeFilter.Add(".jpeg"); 
            openPicker.FileTypeFilter.Add(".png"); 
            // Launch file open picker and caller app is suspended and may be terminated if required 
            openPicker.PickSingleFileAndContinue();
 

To set select photo to Image control you have to add "ContinuationManager.cs" file to project.However see in downloaded sample for this.And finnaly do like this 
C#
 public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args) 
        { 
            if (args.Files.Count > 0) 
            { 
                OutputTextBlock.Text = "Picked photo: " + args.Files[0].Path; 
                var stream = await args.Files[0].OpenAsync(Windows.Storage.FileAccessMode.Read); 
                var bitmapImage = new Windows.UI.Xaml.Media.Imaging.BitmapImage(); 
                await bitmapImage.SetSourceAsync(stream); 
                imagePreivew.Source = bitmapImage; 
            } 
            else 
            { 
                OutputTextBlock.Text = "Operation cancelled."; 
 
            } 
             
            
        }


Note: Please share your thoughts,what you think about this post,Is this post really helpful for you?otherwise it would be very happy ,if you have any thoughts for to implement this requirement in any another way?I always welcome if you drop comments on this post and it would be impressive.


Follow me always at  

Have a nice day by  :)

10 comments:

  1. How to share data to Whatsapp, Facebook, Twitter, and rest other social networks

    ReplyDelete
    Replies
    1. I am not sure about "WhatsApp".But "DataTransferManager" is helpful for share content in windowsphone store 8.1.

      Delete
  2. what about other tasks like Directions task which is absent form wp 8.1 universal app?

    ReplyDelete
  3. How can I launch a Bing search in universal App like we did with the SearchTask in WP 8.0?

    ReplyDelete
    Replies
    1. await Launcher.LaunchUriAsync(new Uri(@"bing://search?q=lady gaga"));

      Delete
  4. Hello Sir,
    I am currently developed album application in windows phone 8.1 store application,
    when I chooes 10 images from Fileopenpicker applicaion get crashed
    Please help me for that

    ReplyDelete
  5. What about Bluetooth sharing.If I want to share some files using Bluetooth as explained below : http://forums.windowscentral.com/windows-phone-8-1/365844-sending-contacts-vcf-file-button-click-via-bluetooth-windows-phone-8-1-a.html

    ReplyDelete
  6. Please help. Is it possible to create a custom ChatMessage to send the Data I want as explained below : http://forums.windowscentral.com/developers-corner/365665-want-add-multiple-contact-sharing-information-windows-phone-8-1-app-developement.html

    ReplyDelete
  7. Wow! these are wonderful tips. Thanks for sharing them with us. Please visit http://goo.gl/URKsAo

    ReplyDelete

Search Engine Submission - AddMe