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


Java ConnectivityManager.CONNECTIVITY_ACTION属性代码示例

本文整理汇总了Java中android.net.ConnectivityManager.CONNECTIVITY_ACTION属性的典型用法代码示例。如果您正苦于以下问题:Java ConnectivityManager.CONNECTIVITY_ACTION属性的具体用法?Java ConnectivityManager.CONNECTIVITY_ACTION怎么用?Java ConnectivityManager.CONNECTIVITY_ACTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.net.ConnectivityManager的用法示例。


在下文中一共展示了ConnectivityManager.CONNECTIVITY_ACTION属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    try {
        String action = intent.getAction();
        if(action == Intent.ACTION_BATTERY_CHANGED){
            handleBattery(intent);
        }else if(action == ConnectivityManager.CONNECTIVITY_ACTION){
            AppModel.getNetworkState();
        }else if(action == Intent.ACTION_SCREEN_ON){
            AppModel.sDevScreenOff = false;
            LogUtils.i("screen on");
        }else if(action == Intent.ACTION_SCREEN_OFF){
            AppModel.sDevScreenOff = true;
            LogUtils.i("screen off");
        }
    }catch (Exception e){
        LogUtils.e("onReceive error ", e);
    }

}
 
开发者ID:XndroidDev,项目名称:Xndroid,代码行数:20,代码来源:XndroidReceiver.java

示例2: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case START_SYNC_ENERGY_USE:
            OhaSyncService.start(context);
            return;
        case Intent.ACTION_BOOT_COMPLETED:
            OhaSyncService.start(context);
            return;
        case ConnectivityManager.CONNECTIVITY_ACTION:
            OhaSyncService.start(context);
            return;

    }
}
 
开发者ID:brolam,项目名称:OpenHomeAnalysis,代码行数:15,代码来源:OhaBroadcast.java

示例3: registerReceiverNet

/***
 * 注册广播监听
 */
void registerReceiverNet() {
    if (mNetworkBroadcastReceiver == null) {
        IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
        mNetworkBroadcastReceiver = new NetworkBroadcastReceiver();
        activity.registerReceiver(mNetworkBroadcastReceiver, intentFilter);
    }
}
 
开发者ID:yangchaojiang,项目名称:yjPlay,代码行数:10,代码来源:ExoUserPlayer.java

示例4: onCreate

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getClass().isAnnotationPresent(ActivityFragmentInject.class)) {
        ActivityFragmentInject annotation = getClass().getAnnotation(ActivityFragmentInject.class);
        hasOptionsMenu = annotation.hasOptionsMenu();
    }
    setHasOptionsMenu(hasOptionsMenu);
    netReceiver = new NetworkReceiver();
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    getActivity().registerReceiver(netReceiver, filter);
}
 
开发者ID:shenhuanet,项目名称:OpenEyesReading-android,代码行数:12,代码来源:BaseFragment.java

示例5: onReceive

@Override
public void onReceive(Context context, Intent intent) {
    switch (intent.getAction()) {
        case ConnectivityManager.CONNECTIVITY_ACTION: {
            ipAddresses = getV4IPAddressesString();
            notifyObservers();
            break;
        }
    }
}
 
开发者ID:Manabu-GT,项目名称:DebugOverlay-Android,代码行数:10,代码来源:IPAddressDataModule.java

示例6: connect

public synchronized void connect() throws MmsRadioException {
  int status = connectivityManager.startUsingNetworkFeature(ConnectivityManager.TYPE_MOBILE,
                                                            FEATURE_ENABLE_MMS);

  Log.w("MmsRadio", "startUsingNetworkFeature status: " + status);

  if (status == APN_ALREADY_ACTIVE) {
    wakeLock.acquire();
    connectedCounter++;
    return;
  } else {
    wakeLock.acquire();
    connectedCounter++;

    if (connectivityListener == null) {
      IntentFilter filter  = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
      connectivityListener = new ConnectivityListener();
      context.registerReceiver(connectivityListener, filter);
    }

    Util.wait(this, 30000);

    if (!isConnected()) {
      Log.w("MmsRadio", "Got back from connectivity wait, and not connected...");
      disconnect();
      throw new MmsRadioException("Unable to successfully enable MMS radio.");
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:29,代码来源:MmsRadio.java

示例7: init

public void init(int version, int layer, int apiId, String deviceModel, String systemVersion, String appVersion, String langCode, String configPath, String logPath, int userId, boolean enablePushConnection) {
    native_init(version, layer, apiId, deviceModel, systemVersion, appVersion, langCode, configPath, logPath, userId, enablePushConnection);
    checkConnection();
    BroadcastReceiver networkStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            checkConnection();
        }
    };
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    ApplicationLoader.applicationContext.registerReceiver(networkStateReceiver, filter);
}
 
开发者ID:MLNO,项目名称:airgram,代码行数:12,代码来源:ConnectionsManager.java

示例8: onCreate

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Creates new IntentFilter that matches a change in network connectivity
    intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

    // Creates new Connection Change Broadcast Receiver
    connectionChange = new ConnectionChange();
}
 
开发者ID:alkathirikhalid,项目名称:connection,代码行数:10,代码来源:ConnectionActivity.java

示例9: testNetworkChangeNotifierMaxBandwidthNotifications

@UiThreadTest
@MediumTest
@Feature({"Android-AppBase"})
public void testNetworkChangeNotifierMaxBandwidthNotifications() throws InterruptedException {
    // Initialize the NetworkChangeNotifier with a connection.
    mConnectivityDelegate.setActiveNetworkExists(true);
    mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_WIFI);
    mWifiDelegate.setLinkSpeedInMbps(1);
    Intent connectivityIntent = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
    mNotifier.resetHasReceivedMaxBandwidthNotification();

    // We shouldn't be re-notified if the connection hasn't actually changed.
    NetworkChangeNotifierTestObserver observer = new NetworkChangeNotifierTestObserver();
    NetworkChangeNotifier.addConnectionTypeObserver(observer);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertFalse(mNotifier.hasReceivedMaxBandwidthNotification());

    // We should be notified if the bandwidth changed but not the connection type.
    mWifiDelegate.setLinkSpeedInMbps(2);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
    mNotifier.resetHasReceivedMaxBandwidthNotification();

    // We should be notified if bandwidth and connection type changed.
    mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_ETHERNET);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
    mNotifier.resetHasReceivedMaxBandwidthNotification();

    // We should be notified if the connection type changed, but not the bandwidth.
    // Note that TYPE_ETHERNET and TYPE_BLUETOOTH have the same +INFINITY max bandwidth.
    // This test will fail if that changes.
    mConnectivityDelegate.setNetworkType(ConnectivityManager.TYPE_BLUETOOTH);
    mReceiver.onReceive(getInstrumentation().getTargetContext(), connectivityIntent);
    assertTrue(mNotifier.hasReceivedMaxBandwidthNotification());
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:38,代码来源:NetworkChangeNotifierTest.java

示例10: onResume

@Override
protected void onResume() {
  super.onResume();

  IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
  registerReceiver(mNetworkStateReceiver, filter);

  isForeground = true;

  //if (Build.VERSION.SDK_INT >= 23) {
  //  requestGPSPermission();
  //}

  Log.d("DEBUG", "onResume..." + scannedMemeList.size());
}
 
开发者ID:tkrworks,项目名称:JinsMemeBRIDGE-Android,代码行数:15,代码来源:MainActivity.java

示例11: NetworkMonitorAutoDetect

/**
 * Constructs a NetworkMonitorAutoDetect. Should only be called on UI thread.
 */
@SuppressLint("NewApi")
public NetworkMonitorAutoDetect(Observer observer, Context context) {
  this.observer = observer;
  this.context = context;
  connectivityManagerDelegate = new ConnectivityManagerDelegate(context);
  wifiManagerDelegate = new WifiManagerDelegate(context);

  final NetworkState networkState = connectivityManagerDelegate.getNetworkState();
  connectionType = getConnectionType(networkState);
  wifiSSID = getWifiSSID(networkState);
  intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);

  if (PeerConnectionFactory.fieldTrialsFindFullName("IncludeWifiDirect").equals("Enabled")) {
    wifiDirectManagerDelegate = new WifiDirectManagerDelegate(observer, context);
  }

  registerReceiver();
  if (connectivityManagerDelegate.supportNetworkCallback()) {
    // On Android 6.0.0, the WRITE_SETTINGS permission is necessary for
    // requestNetwork, so it will fail. This was fixed in Android 6.0.1.
    NetworkCallback tempNetworkCallback = new NetworkCallback();
    try {
      connectivityManagerDelegate.requestMobileNetwork(tempNetworkCallback);
    } catch (java.lang.SecurityException e) {
      Logging.w(TAG, "Unable to obtain permission to request a cellular network.");
      tempNetworkCallback = null;
    }
    mobileNetworkCallback = tempNetworkCallback;
    allNetworkCallback = new SimpleNetworkCallback();
    connectivityManagerDelegate.registerNetworkCallback(allNetworkCallback);
  } else {
    mobileNetworkCallback = null;
    allNetworkCallback = null;
  }
}
 
开发者ID:Piasy,项目名称:AppRTC-Android,代码行数:38,代码来源:NetworkMonitorAutoDetect.java

示例12: initNetworkReceiver

private void initNetworkReceiver() {
    IntentFilter networkActionsFilter =
            new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    networkActionsFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);

    BroadcastReceiver networkActionsReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (mApplicationName == null) return;

            else if (!isConnected()) openConnection(mApplicationName);
        }
    };
    mContext.registerReceiver(networkActionsReceiver, networkActionsFilter);
}
 
开发者ID:metarhia,项目名称:metacom-android,代码行数:15,代码来源:AndroidJSTPConnection.java

示例13: broadcast

public void broadcast() {
  Intent connected = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
  ShadowApplication.getInstance().sendBroadcast(connected);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:DefaultConnectivityMonitorTest.java

示例14: getConnectivityReceivers

private List<BroadcastReceiver> getConnectivityReceivers() {
  Intent connectivity = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
  return ShadowApplication.getInstance().getReceiversForIntent(connectivity);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:DefaultConnectivityMonitorTest.java

示例15: broadcast

void broadcast() {
  Intent connected = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
  ShadowApplication.getInstance().sendBroadcast(connected);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:4,代码来源:DefaultConnectivityMonitorTest.java


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