dotnet cologne 2015 - windows 10 appdev, teil2: coole apis - (daniel meixner)
TRANSCRIPT
NET
XboxIoT
App to AppCommunication
http://windows.Microsoft.com
Today
- Share Contract
- File Picker
- Launch URI
http://windows.Microsoft.com
Launcher.LaunchUriAsync(new Uri(“myapp:?Oh=yes“));
How Do I Link to an App?
http://aka.ms/launchwindowsapp
http://windows.Microsoft.com
Custom schemes work on all platforms.
Spotify:// launches the Spotify app everywhere
Custom Schemes
DEMO
Launch URI
http://windows.Microsoft.com
Launcher.LaunchUriAsync
(new Uri(“myapp:?Oh=no“));
Evil Twin Problem
User/OS chooses target
http://windows.Microsoft.com
Launch specific
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName= “12Me.MyApp";
Launcher.LaunchUriAsync(new Uri(“myapp:?Oh=yes"), options);
http://windows.Microsoft.com
Get the PFN
private string GetPackageFamilyName()
{
return Windows.ApplicationModel.Package.Current.Id.FamilyName;
}
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName= “12Me.MyApp";
string thumbnailToken = SharedStorageAccessManager.AddFile (gpxFile);
var launchUri = new Uri(“myapp:?Oh=yes&file=" + thumbnailToken);
await Launcher.LaunchUriAsync(launchUri, options, inputData);
Launcher.LaunchUriAsync(new Uri(“myapp:?Oh=yes"), options);
//Query for a custom scheme (myapp)
var queryUri = new Uri(“myapp:");
await Launcher.QueryUriSupportAsync(queryUri, LaunchQuerySupportType.Uri);
//Query for a custom scheme supported by a specific app
var queryUri = new Uri(“myapp:");
string packageFamilyName = " 12Me.MyApp ";
await Launcher.QueryUriSupportAsync(queryUri, LaunchQuerySupportType.Uri, packageFamilyName);
//Find all apps that support custom scheme myapp:
var customSchemeProviders = await Launcher.FindUriSchemeHandlersAsync(“myapp");
//Find all apps that can launch a file of type .foo
var fileTypeHandlers = await Launcher.FindFileTypeHandlersAsync(“.foo");
//Find all apps that support custom scheme myapp:
var customSchemeProviders = await Launcher.FindUriSchemeHandlersAsync(“myapp");
//Find all apps that can launch a file of type .foo
var fileTypeHandlers = await Launcher.FindFileTypeHandlersAsync(“.foo");
var resultData = new ValueSet();
resultData.Add("Result", value);
operation.ProtocolForResultsOperation.ReportCompleted(resultData);
App A App B
var options = new LauncherOptions();
options.TargetApplicationPackageFamilyName= “12Me.MyApp";
Launcher.LaunchUriForResultsAsync(new Uri(“myapp-forresults:?Oh=yes"), options);
DEMO
Launch For Results
App Services to AppCommunication
Client App A
Package with App Service
App Service
Background Taskvar conn = new AppServiceConnection();
conn.AppServiceName = “FooAppService”;
conn.PackageFamilyName = “12Me.MyApp“;
var status = await conn.OpenAsync();
Package with App Service
Client App A
App Service
Background Taskvar conn = new AppServiceConnection();
conn.AppServiceName = “FooAppService”;
conn.PackageFamilyName = “12Me.MyApp“;
var status = await conn.OpenAsync();
var message = new ValueSet();
message.Add(“Hi”, “There”);
var r = await conn.SendMessageAsync(message);
conn.Dispose();
Client App A
Client App B
Package with App Service
App Service
Background Task
App Service
Background TaskApp Service Connection
App Service Connection
People
maps
maps
service
CacheExpose
Endpoint
Cortana
Band App
Provide
App service
Client App A
Client App B
Product Scanner
Checkout App
Inventory App
Inventory
Service
Payment Gateway
DEMO
App Services
http://windows.Microsoft.com
Enhanced App to App in Windows 10
Send file token, send data
Launch a *specific* app
App Services
Launch for Results
Shared App Folder
http://windows.Microsoft.com
1. Set breakpoints in app service code
2. Check ‘Do not launch but debug my code when it starts’ in project properties
3. Launch app service foreground app in debugger – nothing happens!
4. Run client app to connect to app service
5. Debugger attaches and breaks on your breakpoint
Debugging an App Service
http://windows.Microsoft.com
Service is activated on-demand
Client may terminate service by disposing its AppServiceConnection
If the invoking app is suspended, app services sponsored by the app will be terminated
Insufficient resources may cause launch failure or service termination
App Service Lifetime
http://windows.Microsoft.com
Wrap your custom scheme or app service in an SDK
Use NuGet to distribute SDK
Use REST-style versioning. For breaking changes, expose a new endpoint
Best Practices
http://windows.Microsoft.com
Windows.System.LauncherLink to a specific app
Pass arbitrary data
Send files
Launch apps for results
Windows.ApplicationModel.AppServicesProvide services to other apps
Consume services provided by other apps
App to App Summary
http://windows.Microsoft.com
Cortana
Office
Interactive Toasts
People/Contacts
Photos
Camera
Who’s Using these APIs?
Bluetooth Ads
http://windows.Microsoft.com
Advertisement Watcher
http://windows.Microsoft.com
Advertisement Publisher
DEMO
BT Advertisment
Trigger
http://windows.Microsoft.com
Trigger based Background Tasks
Apps subscribe to triggers they are interested inOnly run *when* trigger is fired
• Push notification
• Geofencing
• BLE device
• Timer
• Sensors
SystemTrigger
TimeTrigger
MaintenanceTrigger
DeviceUseTrigger
DeviceServicingTrigger
PushNotificationTrigger
CachedFileUpdaterTrigger
DeviceConnectionChangeTrigger
GattCharacteristicNotificationTrigger
RfcommConnectionTrigger
LocationTrigger
AppointmentStoreNotificationTrigger
ContactStoreNotificationTrigger
EmailStoreNotificationTrigger
BluetoothLEAdvertisementWatcherTrigger
BluetoothLEAdvertisementPublisherTrigger
DeviceWatcherTrigger
ActivitySensorTrigger
SensorDataThresholdTrigger
ToastNotificationHistoryChangedTrigger
ToastNotificationActionTrigger
ApplicationTrigger
MediaProcessingTrigger
SocketActivityTrigger
Triggers
NET