简体   繁体   中英

How to create a background application using UWP without UI?

I need to run a BLE Discovery in background and need to show toast when a device found.This is done using UWP with UI . But I need only background application. Is there any way?

Firstly I think that it is good to clarify that even if you want to create UWP app that works in background you have to create normal Universal Windows Application from template in Visual Studio:

在此输入图像描述

Each UWP application can register Background Task to perform some background operations.

You can find the whole implementation guide under below link:

https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/create-and-register-a-background-task

Background task has to be registered by the app so there is no way to create only Background task without the app. Please also remember that application without UI will not pass Windows Store certification.

Lukmanul Hakim,

I have been facing a similar problem and found the best way is through a windows service. In particular:

  • BluetoothLEAdvertisementWatcher works in Windows services, unit test projects, and UWP packages (with the right manifest capabilities).
  • The advertisment watcher executes but does not deliver data/events in WPF desktop apps and .net command line programs.
  • As you note, UWP seems to require annoying UI and can only communicate in a limited way via app services.
  • Once you have the data in a windows service, you can do work there or communicate with any desktop app using regular IPC mechanisms like named pipes.
  • You will need to install the Windows 10 SDK and reference the windows runtime typically at: C:\\Program Files (x86)\\Windows Kits\\10\\UnionMetadata\\Windows.winmd

For reference here is the basic code to get advertisments:

 var watcher = new BluetoothLEAdvertisementWatcher(); 
 watcher.Received += OnAdvertismentReceived;                      
 watcher.Start();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM