- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我想在手机锁定时接收来自 wifi 的数据包。问题是当我锁定屏幕时,我的前台服务停止接收数据包。我正在使用这样的前台服务:
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
var notification = new Notification.Builder(this)
.SetContentTitle(Resources.GetString(Resource.String.app_name))
.SetContentText(Resources.GetString(Resource.String.notification_text))
.SetSmallIcon(Resource.Drawable.ic_stat_name)
.SetContentIntent(BuildIntentToShowMainActivity())
.SetOngoing(true)
.AddAction(BuildRestartTimerAction())
.AddAction(BuildStopServiceAction())
.Build();
// Enlist this instance of the service as a foreground service
StartForeground(Constants.SERVICE_RUNNING_NOTIFICATION_ID, notification);
/*DO THIS EVEN WHEN SCREEN IS LOCKED*/
var powerManager = (PowerManager)GetSystemService(PowerService);
_wakeLock = powerManager.NewWakeLock(WakeLockFlags.Partial, "WakeLockTag");
_wakeLock.Acquire();
var wifiManager = (WifiManager)GetSystemService(WifiService);
_wifiLock = wifiManager.CreateWifiLock(WifiMode.FullHighPerf, "xamarin_wifi_lock");
_wifiLock.Acquire();
if (!powerManager.IsIgnoringBatteryOptimizations("com.xamarin.xample.foregroundservicedemo") ||
!_wakeLock.IsHeld || !_wifiLock.IsHeld)
throw new InvalidOperationException("OPTIMIZATIONS NOT ACTIVE");
string msg = timestamper.GetFormattedTimestamp();
Log.Debug(TAG, msg);
Intent intent = new Intent(Constants.NOTIFICATION_BROADCAST_ACTION);
intent.SetAction(Android.Provider.Settings.ActionIgnoreBatteryOptimizationSettings);
intent.PutExtra(Constants.BROADCAST_MESSAGE_KEY, msg);
LocalBroadcastManager.GetInstance(this).SendBroadcast(intent);
Task.Run(() =>
{
using (var client = new UdpClient(12345))
{
while (true)
{
var result = client.ReceiveAsync().Result;
Console.WriteLine($"RECEIVED: {result.Buffer.Length}");
}
}
});
return StartCommandResult.Sticky;
}
我正在做以下事情来确保它没有被杀死:
StartCommandResult.Sticky
Never
(我在手机中设置了设置)ActionIgnoreBatteryOptimizationSettings
我还缺少什么?我正在使用带有 Android 6.0 - API 23 的三星 A5。
我从 adb 命令提示符查看了日志,并检查了我的服务实际上是作为前台服务运行的,并且所有锁都被持有。
最佳答案
你所做的很好,一切都很好。 但是!!
让我们来看看devleport.android.com的帖子:
Google Play policies prohibit apps from requesting direct exemption from Power Management features in Android 6.0+ (Doze and App Standby) unless the core function of the app is adversely affected.
你说:
I am using Samsung A5 with Android 6.0 - API 23.
也就是说,当手机进入休眠状态时,您将无法保持前台服务,因为应用的核心功能 没有 受到不利影响.
这就是您注意到手机处于 sleep 状态时停止接收数据包的原因。
请浏览我附加的整个链接以及我们的 Power Manager指导。
编辑:我现在注意到了:
If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps' access to network and CPU-intensive services. It also prevents apps from accessing the network and defers their jobs, syncs, and standard alarms.
打瞌睡限制:
这将结束我对您所有问题的回答。
编辑 2:
我进一步调查了一下,在 Xamarin.Android 中有一篇关于这个问题的完整帖子。 .
还有一个解决方案是每 10 分钟唤醒一次手机以绕过它here .
关于c# - 手机进入休眠状态后,在前台服务中保持 wifi 处于 Activity 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51684502/
我想检查 wifi 是否有互联网连接。大多数解决方案/方法(包括 alamofire)仅在设备仅连接到 wifi 时才返回 true,不检查 wifi 是否有互联网连接。 最佳答案 苹果的reacha
是否可以通过 wifi 网络发送一些弹出消息或短信/彩信?如果是如何发送。 我的用例是向连接到我的开放 wifi 网络的设备发送某种弹出窗口。弹出窗口可以是图形广告或任何信息之类的东西。 任何人都可以
假设您对无线路由器有完全的编程控制(运行 OpenWrt 或 DD-WRT - Linux)。路由器配置为广播 ssid,并且网络完全开放。 移动用户(iPhone/Android/BB)走过来。 1
我正在编写一个 Android 应用程序,并试图弄清楚是否有可靠的方法来确定手机何时连接到特定的 wifi 网络。 例如,我只想在连接到家庭 wifi 时执行某些操作。 有人知道这是否可行吗? 最佳答
我想把我的 Raspberry PI 3 变成类似 WiFi 信号放大器、无线中继器/扩展器或 WiFi 热点之类的东西,可以放大微弱的 WiFi 信号。 经过一番研究,我找到了这个教程,点击 her
我目前正在使用我的 mongodb 服务器以及正在运行的 Nodejs 服务器测试我的 Android 应用程序。我希望服务器可以像内联网一样通过 WiFi 访问,以便手机上的应用程序可以访问本地服务
问题陈述 调用pcap_activate()结果 PCAP_ERR_RFMON_NOTSUP错误,即不支持射频监控模式。 上下文 我正在编写小型 C 程序,其工作是在监听模式下监听笔记本电脑的 wif
想象一下这种情况,周围有一些智能手机和计算机,它们的 WiFi 适配器(无线适配器)打开,但没有必要连接到网络。 有没有办法通过 Linux 机器查看 MAC 地址? 任何见解表示赞赏。 最佳答案 断
我在 WiFi 连接检测方面遇到问题。我的目标是检测用户何时在不同的 WiFi 之间切换。我发现this ,但它只检测 WiFi 何时建立。就我而言,我需要知道手机上的一个 WiFi 网络何时更改为另
我想获取一些有关 Wifi 的信息,例如 SSID 名称、IP 地址和速度,所以我编写了这段代码 WifiManager wifiMgr = (WifiManager) getSystemServic
我正在安装一个系统来监控一些传感器,并根据它们打开/关闭几盏灯。 为了进一步的数据分析,我们还想将该数据发送到中央服务器,因此我们添加了 Wifi 屏蔽。 请记住,如果没有网络,系统应该可以正常运行。
这两天我一直在苦苦挣扎,我找不到解决办法。我尝试了这段代码,但随着时间的推移,它在 Android 5(Lollipop) 上运行,但在 7.1.1.(Nougat) 上不起作用。我有另一个场景,手机
我正在开发一些软件来管理通过 ZigBee 与 Remote 通信的设备。我们希望设备能够通过 Wi-Fi 与网络服务器和/或智能手机通信,以便我们的软件可以与之交互。 ZigBee Remote 很
自 setWifiEnabled在 Android 10 上已弃用,如何在 Android 10 设备上以编程方式启用 wifi? 是否无法在 Android 10+ (SDK 29) 上以编程方式启
我正在尝试从 WiFi 数据包中获取 RSSI 或信号强度。 我还想要来自“WiFi 探测请求”的 RSSI(当有人在搜索 WiFi 热点时)。 我设法从 kismet 日志中看到它,但这只是为了确保
关闭。这个问题是not reproducible or was caused by typos .它目前不接受答案。 此问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-topic
我需要一个 IOS 应用程序,用户将在其中启动应用程序,录制音频语音(通过设备麦克风),该语音语音将广播给同一网络上的其他用户,所有这些都必须通过无线连接(WIFI)进行直播。 我对可能的解决方案进行
更新: 我指出了问题的来源。为了避免任何复杂化,我使用 ScanNetwork 示例,所以我什至不必输入 SSID .该代码在遇到 WiFi.status() 后立即停止在板上运行. 我有一个 Ser
在我的 android 应用程序中,我连接到 WiFi 网络。但是,例如,如果我多次连接到这个网络,这个网络的名称就会多次出现在标准的 android WiFi 列表中。我怎样才能避免这种情况? 我的
我有可用的 wifi 网络列表列表,现在我想连接到特定网络。所以请指导我在 ListView 中获取网络列表后必须做什么。 **package com.example.wifilist imp
我是一名优秀的程序员,十分优秀!