startLocalOnlyHotspot 和创建热点的编程部分。

huangapple go评论58阅读模式
英文:

startLocalOnlyHotspot and create hotspot programaticaly

问题

startLocalOnlyHotspot 和创建热点的编程方式

我尝试以编程方式创建一个类似于此应用的热点,但问题是热点创建后立即消失。

以下是我正在使用的代码:

private val wifiManager: WifiManager by lazy {
    (applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager)
}

startLocalOnlyHotspot(object : WifiManager.LocalOnlyHotspotCallback() {
    override fun onStarted(reservation: WifiManager.LocalOnlyHotspotReservation) {
        super.onStarted(reservation)
    }

    override fun onStopped() {
        super.onStopped()
    }

    override fun onFailed(reason: Int) {
        super.onFailed(reason)
    }
}, Handler(Looper.getMainLooper()))

我还尝试过使用前台服务和 WorkManager,但没有成功。当我检查我的 logcat 时,我看到热点被创建,但立即消失,并显示以下错误消息:

系统资源无法调用 close。

英文:

startLocalOnlyHotspot and create hotspot programaticaly

I am trying to create a hotspot programmatically similar to this app my problem is hotspot
create and immediately disappear

Here is the code I am using:

   private val wifiManager: WifiManager by lazy {
    (applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager)
}



   startLocalOnlyHotspot(object : WifiManager.LocalOnlyHotspotCallback() {
            override fun onStarted(reservation: WifiManager.LocalOnlyHotspotReservation) {
                super.onStarted(reservation)
            }

            override fun onStopped() {
                super.onStopped()
            }

            override fun onFailed(reason: Int) {
                super.onFailed(reason)
            }
        }, Handler(Looper.getMainLooper()))

I have also tried this code with foreground service and WorkManager but it did not work. When I check my logcat, I see that the hotspot is created but disappears immediately with the following error message:
> System resource failed to call close.

答案1

得分: 0

reservation对象保留为字段,像这样:

private WifiManager.LocalOnlyHotspotReservation reservation
英文:

keep the reservation object as a field like this :

private WifiManager.LocalOnlyHotspotReservation reservation

huangapple
  • 本文由 发表于 2023年5月7日 05:14:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76191167.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定