本文整理汇总了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);
}
}
示例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;
}
}
示例3: registerReceiverNet
/***
* 注册广播监听
*/
void registerReceiverNet() {
if (mNetworkBroadcastReceiver == null) {
IntentFilter intentFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
mNetworkBroadcastReceiver = new NetworkBroadcastReceiver();
activity.registerReceiver(mNetworkBroadcastReceiver, intentFilter);
}
}
示例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);
}
示例5: onReceive
@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case ConnectivityManager.CONNECTIVITY_ACTION: {
ipAddresses = getV4IPAddressesString();
notifyObservers();
break;
}
}
}
示例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.");
}
}
}
示例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);
}
示例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();
}
示例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());
}
示例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());
}
示例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;
}
}
示例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);
}
示例13: broadcast
public void broadcast() {
Intent connected = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
ShadowApplication.getInstance().sendBroadcast(connected);
}
示例14: getConnectivityReceivers
private List<BroadcastReceiver> getConnectivityReceivers() {
Intent connectivity = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
return ShadowApplication.getInstance().getReceiversForIntent(connectivity);
}
示例15: broadcast
void broadcast() {
Intent connected = new Intent(ConnectivityManager.CONNECTIVITY_ACTION);
ShadowApplication.getInstance().sendBroadcast(connected);
}