本文整理汇总了Java中android.net.NetworkRequest.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java NetworkRequest.Builder方法的具体用法?Java NetworkRequest.Builder怎么用?Java NetworkRequest.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.net.NetworkRequest
的用法示例。
在下文中一共展示了NetworkRequest.Builder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: requestMobileNetwork
import android.net.NetworkRequest; //导入方法依赖的package包/类
/** Only callable on Lollipop and newer releases. */
@SuppressLint("NewApi")
public void requestMobileNetwork(NetworkCallback networkCallback) {
NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR);
connectivityManager.requestNetwork(builder.build(), networkCallback);
}
示例2: onResume
import android.net.NetworkRequest; //导入方法依赖的package包/类
@Override
protected void onResume() {
super.onResume();
// Register network callbacks
ConnectivityManager connectivityManager =
(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
networkCallback = new NetworkCallback(this);
NetworkRequest.Builder networkRequestBuilder = new NetworkRequest.Builder();
networkRequestBuilder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
connectivityManager.registerNetworkCallback(
networkRequestBuilder.build(), networkCallback);
}
示例3: requestNetwork
import android.net.NetworkRequest; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void requestNetwork(Context context) {
if (!Utils.postVersion(Build.VERSION_CODES.LOLLIPOP)) {
return;
}
setUpConnectivityManager(context);
NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET);
builder.addTransportType(NetworkCapabilities.TRANSPORT_WIFI);
if (mCallback != null) {
try {
mConnectivityManager.unregisterNetworkCallback(mCallback);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
}
mCallback = new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
if (mCallback != null) {
if (Utils.postVersion(Build.VERSION_CODES.M)) {
mConnectivityManager.bindProcessToNetwork(network);
} else {
ConnectivityManager.setProcessDefaultNetwork(network);
}
}
}
};
mConnectivityManager.requestNetwork(builder.build(), mCallback);
}
示例4: registerNetworkCallbacks
import android.net.NetworkRequest; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void registerNetworkCallbacks(MerlinService.ConnectivityChangesNotifier connectivityChangesNotifier) {
NetworkRequest.Builder builder = new NetworkRequest.Builder();
connectivityManager.registerNetworkCallback(builder.build(), connectivityCallbacks(connectivityChangesNotifier));
}