1
DONG NAI UNIVERSITY OF TECHNOLOGY
6. Extending the Photos Hub
5. Capturing photos
3. Acquiring a single photo
2. Search extensibility
1. Launchers and Choosers
7. Lenses
8. Sharing photos
4. Working with the media library
2
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Both Launchers and Choosers are API mechanisms for invoking existing apps and services on the phone. In the API, they’re all called “tasks.”
The difference between Launchers and Choosers is that Launchers start a feature but don’t return a value, whereas Choosers launch a feature and do return a value.
Invoking a Launcher or Chooser causes your app (the invoking app) to be deactivated.
using Microsoft.Phone.Tasks;
3
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
User guide: Launchers for Windows Phone:http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769550(v=vs.105).aspx User guide: Choosers for Windows Phone:http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff769543(v=vs.105).aspx
4
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Launchers
Task Description
BingMapsDirectionsTask Launches the Maps app, specifying a starting and/or ending location, for which driving or walking directions are displayed (identical to the MapsDirectionsTask).
BingMapsTask Launches the Maps app centered at the specified or current location (identical to the MapsTask)
ConnectionSettingsTask Launches a settings dialog with which the user can change the device’s connection settings
EmailComposeTask Composes a new email
MapDownloaderTask Provides a mechanism for the user to download maps for offline use
MapUpdaterTask Provides a mechanism for the user to update map data he has previously downloaded for offline use.
5
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Launchers
Task Description
MapsDirectionsTask Launches the Maps app, specifying a starting and/or ending location, for which driving or walking directions are displayed (identical to BingMapsDirectionsTask).
MapsTask Launches the Maps app centered at the specified or current location (identical to BingMapsTask)
MarketplaceDetailTask Launches the Windows Phone Store and displays the details for a specific app
MarketplaceHubTask Launches the Windows Phone Store and searches for a particular type of content
MarketplaceReviewTask Displays the Windows Phone Store review page for the current app
MarketplaceSearchTask Launches the Windows Phone Store and displays the search results from the specified search terms.
6
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Launchers
Task Description
MediaPlayerLauncher Launches Media Player, and plays the specified media file
PhoneCallTask Initiates a phone call to a specified number.
SaveAppointmentTask Provides a mechanism for the user to save an appointment from your app
SearchTask Launches Microsoft Bing Search with a specified search term
ShareLinkTask Launches a dialog with which the user can share a link on the social networks of her choice. If the user does not have any social networks set up, the Launcher silently fails
ShareMediaTask Provides a mechanism for your app to share a media item with one of the media-sharing apps on the phone
7
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Launchers
Task Description
ShareStatusTask Launches a dialog with which the user can share a status message on the social networks of her choice. If the user does not have any social networks set up, the Launcher silently fails
SmsComposeTask Composes a new text message.
WebBrowserTask Launches Microsoft Internet Explorer and browses to a specific URI
8
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Choosers
Task Description
AddWalletItemTask Launches the Wallet app and allows the user to add the supplied item to his wallet
AddressChooserTask Launches the Contacts app with which the user can find an address.
CameraCaptureTask Opens the Camera app to take a photo
EmailAddressChooserTask Provides a mechanism for the user to select an email address from his Contacts List.
GameInviteTask Shows the game invite screen with which the user can invite players to a multiplayer game session.
PhoneNumberChooserTask Provides a mechanism for the user to select a phone number from his Contacts List
9
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
Choosers
Task Description
PhotoChooserTask Provides a mechanism for the user to select an image from his Picture Gallery or take a photo
SaveContactTask Launches the Contacts app with which the user can save a contact.
SaveEmailAddressTask Saves an email address to an existing or new contact.
SavePhoneNumberTask Saves a phone number to an existing or new contact
SaveRingtoneTask Launches the Ringtones app with which the user can save a ringtone from your app to the system ringtones list
10
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
The basic steps for using a Launcher are as follows:
1. Create an instance of the type that represents the
specific Launcher feature that you want to use.
2. Set properties on the object as appropriate.
3. Invoke the Show method
11
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
The basic steps for using a Launcher are as follows:
Simple Example for SMS message:
SmsComposeTask smsTask = new SmsComposeTask(); smsTask.To = "0987773061"; smsTask.Body = "Alô Năm M i ! m i h n năm cũ"ớ ớ ơ ; smsTask.Show();
12
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
The basic steps for using a Chooser are as follows:
1. Create an instance of the type that represents the specific
Chooser feature that you want to use. It is common to declare
this as a field in your page class.
2. Hook up the Completed event on the object (or provide an
inline delegate or lambda), which will be invoked when the
Chooser task completes.3. Set properties on the object as appropriate.4. Invoke the Show method.5. In your Completed event handler or delegate, process the return value from the Chooser.
13
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
The basic steps for using a Chooser are as follows:
Simple Example for PhoneNumberChooserTask :PhoneNumberChooserTask pnChooserTask;
private void Button_Click_1(object sender, RoutedEventArgs e) { pnChooserTask = new PhoneNumberChooserTask(); pnChooserTask.Completed += new EventHandler<PhoneNumberResult>(pnChooserTask_Completed); pnChooserTask.Show(); }
14
DONG NAI UNIVERSITY OF TECHNOLOGY
1. Launchers and Choosers
void pnChooserTask_Completed(object sender, PhoneNumberResult e) {if (e.TaskResult == TaskResult.OK) { MessageBox.Show("The phone number for " + e.DisplayName + " is " + e.PhoneNumber);
PhoneCallTask phoneCallTask = new PhoneCallTask(); phoneCallTask.DisplayName = e.DisplayName; phoneCallTask.PhoneNumber = e.PhoneNumber; phoneCallTask.Show(); } }
PhoneCallTask is protected by the ID_CAP_PHONEDIALER capability
15
DONG NAI UNIVERSITY OF TECHNOLOGY
2. Search extensibility
Another way that your app can communicate with standard phone services is by extending the Bing search experience with custom behavior, integrating your app seamlessly with the search results.
There are two ways by which you can extend the Bing search behavior in your apps: App Connect and App Instant Answer. With both features, you can set up your app so that it shows up in the Bing search results when the user taps the hardware Search button
Please visit this link to learn more: http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh286420(v=vs.105).aspx
16
DONG NAI UNIVERSITY OF TECHNOLOGY
2. Search extensibility
Requirement App Connect App Instant Answer
WMAppManifest.xml Requires Extensions entries for each Bing category that you want to extend
No specific changes required
Extras.xml Required. Specifies captions to be used in the search results apps pivot item.
Not used
UriMapper Recommended. Allows you to re-route to a specific page on app startup.
Not required
Target page You can re-route to multiple different pages, depending on the search item, if you want.
No option. Your app is launched as normal, with its default startup page
17
DONG NAI UNIVERSITY OF TECHNOLOGY
2. Search extensibility
Requirement App Connect App Instant Answer
Query string You should parse the incoming query string for categories and item names for which you want to provide extensions
You should parse the incoming query string for the bing_query value.
Search connection Bing includes your app in the search results when the user’s search matches the categories for which you registered extensions.
Bing includes your app in the search results, based on whether it thinks the query is relevant to your app.
18
DONG NAI UNIVERSITY OF TECHNOLOGY
2. Search extensibility
The App Connect extensibility model
19
DONG NAI UNIVERSITY OF TECHNOLOGY
2. Search extensibility
The App Instant Answer extensibility model
20
DONG NAI UNIVERSITY OF TECHNOLOGY
3. Acquiring a single photo
Many apps need to provide the option to acquire a single photo from the user, either selected from the media library or captured by the camera. Windows Phone offers built-in tasks that make this process simple: PhotoChooserTask and CameraChooserTask
using Microsoft.Phone.Tasks;using System.Windows.Media.Imaging;
21
DONG NAI UNIVERSITY OF TECHNOLOGY
3. Acquiring a single photo
PhotoChooserTask photoChooser = new PhotoChooserTask();photoChooser.Completed += photoChooser_Completed;photoChooser.Show();
private void photoChooser_Completed(object sender, PhotoResult e) { if (e.TaskResult != TaskResult.OK) { return; } BitmapImage image = new BitmapImage(); image.SetSource(e.ChosenPhoto); myimage.Source = image; }
22
DONG NAI UNIVERSITY OF TECHNOLOGY
4. Working with the media library
The Media Library APIs in the XNA framework facilitate deeper integration with the user’s photos collection
using Microsoft.Xna.Framework.Media;
Reading photos
Adding new images
23
DONG NAI UNIVERSITY OF TECHNOLOGY
4. Working with the media library
This list is populated in the OnNavigatedTo method of the AlbumListPage. All of the photo albums available on the device are found under the RootPictureAlbum of the MediaLibrary.
protected override void OnNavigatedTo(NavigationEventArgs e) { using (MediaLibrary mLib = new MediaLibrary()) { mylistbox.ItemsSource = mLib.RootPictureAlbum.Albums; } }
ID_CAP_MEDIALIB_PHOTO capability
24
DONG NAI UNIVERSITY OF TECHNOLOGY
4. Working with the media library
The Pictures property returns all of the photos in the user’s library as a single collection, whereas the RootPictureAlbum property returns a collection of PictureAlbum instances, which correspond to the individual user photo albums:
foreach (PictureAlbum picAlbum in mediaLibrary.RootPictureAlbum.Albums){ foreach (Picture pic in picAlbum.Pictures) { BitmapImage bitMap = new BitmapImage(); bitMap.SetSource(pic.GetImage()); Image img = new Image();//Process Image here img.Source = bitMap; }}
25
DONG NAI UNIVERSITY OF TECHNOLOGY
4. Working with the media libraryint pictureCollectionSize;PictureCollection pictureCollection;public void createPictureSlideShow() { slideshowPivot.Items.Clear(); pictureCollection = picAlbum.Pictures; pictureCollectionSize = pictureCollection.Count; for (int i = 0; i < pictureCollectionSize; i++) { PivotItem pitem = new PivotItem(); pitem.Header = "Hình " + (i + 1); BitmapImage bitMap = new BitmapImage(); bitMap.SetSource(pictureCollection[i].GetImage()); Image img = new Image(); img.Source = bitMap; img.Stretch = Stretch.Fill; pitem.Content = img; slideshowPivot.Items.Add(pitem); } }
26
DONG NAI UNIVERSITY OF TECHNOLOGY
4. Working with the media library
Adding new images
var mediaLibrary = new MediaLibrary();var targetJpegStream = new MemoryStream();
grayscaleImage.SaveJpeg(targetJpegStream, grayscaleImage.PixelWidth,grayscaleImage.PixelHeight, 0, 100);
targetJpegStream.Seek(0, SeekOrigin.Begin);
string grayscaleFilename = "gray_hinh_moi";mediaLibrary.SavePicture(grayscaleFilename, targetJpegStream);
27
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera in Microsoft.Devices namespace and PhotoCaptureDevice in Windows.Phone.Media.Capture
To build the photo preview and capture experience directly in the app, enabling camera apps that go beyond the built-in functionality.
Capabilities:ID_CAP_ISV_CAMERA ,ID_CAP_MEDIALIB_PHOTO
28
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera class
Using VideoBrush to display Camera
Tab on surface to capture photos
MainPage.xaml
29
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera class
Coding MainPage
using Microsoft.Devices;using Microsoft.Xna.Framework.Media;using System.Windows.Media;
PhotoCamera camera;protected override void OnNavigatedTo(NavigationEventArgs e){ base.OnNavigatedTo(e); camera = new PhotoCamera(CameraType.Primary); camera.Initialized += camera_Initialized; viewFinderVideoBrush.SetSource(camera);}
30
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera class
Coding MainPage
void camera_Initialized(object sender, CameraOperationCompletedEventArgs e){ if (e.Succeeded) { //Press Camera Button on Real Device CameraButtons.ShutterKeyPressed += CameraButtons_ShutterKeyPressed; //Available to capture photo to library camera.CaptureImageAvailable += camera_CaptureImageAvailable; camera.FlashMode = FlashMode.Auto; } }
31
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera class
Coding MainPage
void CameraButtons_ShutterKeyPressed(object sender, EventArgs e) { try { //User pressed the Camera Button on Physical device camera.CaptureImage(); } catch (InvalidOperationException ex) { } }Tap event on the canvas:private void viewFinderCanvas_Tap(object sender, System.Windows.Input.GestureEventArgs e){//Call CaptureImage method here}
32
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera class
Coding MainPage
Auto Save Picture To Camera Roll if Image is Availablevoid camera_CaptureImageAvailable(object sender, ContentReadyEventArgs e) { string path = "picture" + DateTime.Now.ToString("YYYYMMDDHHMMSSmmmm") + ".jpg"; MediaLibrary library = new MediaLibrary(); library.SavePictureToCameraRoll(path, e.ImageStream);
}
33
DONG NAI UNIVERSITY OF TECHNOLOGY
5. Capturing photos
PhotoCamera class
Coding MainPage
Auto change Camera Orientation If device is rotatedprotected override void OnOrientationChanged (OrientationChangedEventArgs e) { if (Orientation == PageOrientation.LandscapeRight) { viewFinderVideoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 180 }; } else { viewFinderVideoBrush.RelativeTransform = new CompositeTransform() { CenterX = 0.5, CenterY = 0.5, Rotation = 0 }; } base.OnOrientationChanged(e); }
34
DONG NAI UNIVERSITY OF TECHNOLOGY
6. Extending the Photos Hub
Apps pivot
The simplest form of Photos Hub extensibility is the ability to be included in the apps pivot
<Extensions> <Extension ExtensionName="Photos_Extra_Hub"ConsumerID="{5B04B775-356B-4AA0-AAF8-6491FFEA5632}"TaskID="_default" /></Extensions>
35
DONG NAI UNIVERSITY OF TECHNOLOGY
7. Lenses
Lenses are camera apps that can be launched directly from the built-in camera app and which naturally complement it by using the camera sensor to provide a specialized experience
36
DONG NAI UNIVERSITY OF TECHNOLOGY
8. Sharing photos
Users don’t want to just take photos; they want to share them, too. With Windows Phone, apps can participate in this sharing flow, whether the user is explicitly sharing a photo through the ShareMediaTask or automatically uploading them to the cloud by using auto-upload
37
DONG NAI UNIVERSITY OF TECHNOLOGY
8. Sharing photos
<Capability Name="ID_CAP_MEDIALIB_PHOTO" />
<Extensions> <Extension ExtensionName="Photos_Extra_Share" ConsumerID= "{5B04B775-356B-4AA0-AAF8-6491FFEA5632}" TaskID="_default" /></Extensions>
WMAppManifest.xml
38
DONG NAI UNIVERSITY OF TECHNOLOGY
8. Sharing photos
protected override void OnNavigatedTo(NavigationEventArgs e) {IDictionary<string, string> queryStrings = this.NavigationContext.QueryString;if (queryStrings.ContainsKey("FileId")) { MediaLibrary library = new MediaLibrary(); Picture photoFromLibrary = library.GetPictureFromToken(queryStrings["FileId"]); BitmapImage bitmapFromPhoto = new BitmapImage(); bitmapFromPhoto.SetSource(photoFromLibrary.GetPreviewImage()); image1.Source = bitmapFromPhoto; } }
Coding MainPage
39
DONG NAI UNIVERSITY OF TECHNOLOGY
END