Answer the question
In order to leave comments, you need to log in
How to implement application control on Windows using Android?
There is a simple application, for example, just a form with text (with a label).
There is an application on android, roughly speaking, with a simple regular button.
When you click on the button, the label text should change to another desired one. How can this be implemented? Both devices (phone and PC) are connected to the same network (can be connected via cable if needed)
Answer the question
In order to leave comments, you need to log in
Send request from android
POST https://you_server_api/api/power
{
"mode": "on"
}
var baseAdress = new Uri(Properties.Settings.Default.BaseUri);
var server = new WebApiServer(baseAdress);
server.Start();
var message = $"Web API Self hosted on {baseAdress} Hit ENTER to exit...";
_logger.Info(message);
System.Console.ReadLine();
server.Stop();
return (int)ScanerStatus.Ok;
using NLog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.SelfHost;
namespace RO.WebScaner.Console
{
/// <summary>
/// Web api server implementation
/// </summary>
public class WebApiServer
{
Logger _logger = LogManager.GetCurrentClassLogger();
Uri _uri;
HttpSelfHostServer _server;
/// <summary>
/// Create instance of Webapi embedd server
/// </summary>
/// <param name="uri">Endpoint address</param>
public WebApiServer(Uri uri)
{
_uri = uri;
}
/// <summary>
/// Start web api server.
/// </summary>
/// Команда для запуска исключения файрвола
/// netsh http add urlacl url=http://+:8000/ user=ZOOPLAZA-PC\developer
/// <remarks>
/// </remarks>
public void Start()
{
_logger.Info("Start WebApi server");
HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(_uri);
config.EnableCors();
ConfigRoutes(config);
ConfigFormatter(config);
_server = new HttpSelfHostServer(config);
_server.OpenAsync().Wait();
}
/// <summary>
/// Remove xml formatter, maybe in future add binary formatter
/// </summary>
/// <param name="config"></param>
private static void ConfigFormatter(HttpSelfHostConfiguration config)
{
// remove xml
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
/// <summary>
/// Config web api routes
/// </summary>
/// <param name="config"></param>
private static void ConfigRoutes(HttpSelfHostConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
public void Stop() {
_server.CloseAsync().Wait();
_logger.Info("Close WebApi server");
}
}
}
using NLog;
using RO.WebScaner.Console.Models;
using RO.WebScaner.Core;
using RO.WebScaner.Interfaces;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Cors;
namespace RO.WebScaner.Console.Controllers
{
public class ListController : ApiController
{
Logger _logger;
/// <summary>
/// Logger with delay load
/// </summary>
public Logger Logger
{
get
{
if (_logger == null)
{
_logger = LogManager.GetCurrentClassLogger();
}
return _logger;
}
set { _logger = value; }
}
[EnableCors(origins: "*",headers: "*", methods:"*")]
public IHttpActionResult Get()
{
try
{
var model = Worker.List();
return Ok(model);
}
catch(Exception e)
{
Logger.Error(e);
return InternalServerError(e);
}
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question