当前位置: 首页>>代码示例>>Java>>正文


Java NetworkRequest.Builder方法代码示例

本文整理汇总了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);
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:9,代码来源:NetworkMonitorAutoDetect.java

示例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);

}
 
开发者ID:jkozh,项目名称:stockhawk,代码行数:15,代码来源:MainActivity.java

示例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);
}
 
开发者ID:kuastw,项目名称:KUAS-Wifi-Auto-Login,代码行数:36,代码来源:Utils.java

示例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));
}
 
开发者ID:novoda,项目名称:merlin,代码行数:6,代码来源:ConnectivityChangesRegister.java


注:本文中的android.net.NetworkRequest.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。