Closed. This question needs debugging details。它当前不接受答案。
                        
                    
                
            
        
            
        
                
                    
                
            
                
                    想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                
                    2个月前关闭。
            
        

    

我在小米设备中出现错误,即使启用了小米设备,系统也会不断询问移动数据权限
错误“移动数据已禁用,应用程序需要将其激活,是否要进行设置以激活它们?”错误。
即使单击“是”,也不会转到移动数据设置。
有人知道发生了什么吗?

我正在使用最低API 20的Anroid SDK版本29

最佳答案

// implement this on build.gradle

implementation 'com.github.pwittchen:reactivenetwork-rx2:0.13.0'

// Add This On Your Activity / Fragment (Kotlin)

    private var connectivityDisposable: Disposable? = null
    private var internetDisposable: Disposable? = null

    var mTAG: String = "activity/FragmentName : "

@SuppressLint("SetTextI18n")
    override fun onResume() {
        super.onResume()
        connectivityDisposable = ReactiveNetwork.observeNetworkConnectivity(context)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { connectivity ->
                Constant.logD(mTAG, "Connectivity : ", connectivity.toString())
                val state = connectivity.state()
                val name = connectivity.typeName()
                Constant.logD(
                    mTAG,
                    "Connectivity Disposable : ",
                    String.format("state: %s, typeName: %s", state, name)
                )
            }

        internetDisposable = ReactiveNetwork.observeInternetConnectivity()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { isConnectedToInternet ->
                Constant.logD(mTAG, "Internet Disposable : ", isConnectedToInternet.toString())
                 // Here You Can Use Snackbar Bases On isConnectedToInternet
                 // isConnectedToInternet - True - Network Available
                // isConnectedToInternet - False - Network UnAvailable
            }
    }

    override fun onPause() {
        super.onPause()
        safelyDispose(connectivityDisposable)
        safelyDispose(internetDisposable)
    }

    private fun safelyDispose(disposable: Disposable?) {
        if (disposable != null && !disposable.isDisposed) {
            disposable.dispose()
        }
    }

07-25 21:05