我有一個版本的Android M預覽3.
在我的應用程序同樣的錯誤,我用ConnectivityManager調用requestNetwork()函數
requestNetwork(NetworkRequest, NetworkCallback)
爲建設NetworkRequest我使用此代碼
android.net.NetworkRequest.Builder builder = new android.net.NetworkRequest.Builder();
builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
builder.removeTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
添加能力參數後,崩潰消失
android.net.NetworkRequest.Builder builder = new android.net.NetworkRequest.Builder();
builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
builder.removeTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
builder.addCapability(NetworkCapabilities.TRANSPORT_CELLULAR);
builder.addCapability(NetworkCapabilities.TRANSPORT_WIFI);
我無法在清單中添加該權限,因爲它是系統級權限。當我調用ConnectivityManager requestNetwork method時,它會崩潰。我必須儘快解決此問題。我不明白爲什麼會發生這種情況。 – user1010876