Code work when App is an Background(minimize state)but not working when App is an kill state after bridging with react native
See original GitHub issueService running with android studio working for both background and kill state but not working after bridging with react native,run with react native it only work when app is an background(minimize) state.
react-native version
System: OS: Windows 10 CPU: (4) x64 Intel® Core™ i5-5200U CPU @ 2.20GHz Memory: 1.18 GB / 7.93 GB Binaries: Node: 11.11.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.15.2 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 6.7.0 - C:\Program Files\nodejs\npm.CMD SDKs: Android SDK: API Levels: 23, 25, 26, 28 Build Tools: 28.0.3 System Images: android-26 | Google Play Intel x86 Atom, android-28 | Intel x86 Atom IDEs: Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842 npmPackages: react: 16.9.0 => 16.9.0 react-native: 0.61.2 => 0.61.2,
here are my Nethelper class
`package com.check_net;
import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; import android.content.IntentFilter; import android.content.Context; import android.content.Intent; import android.os.Bundle;
public class NetHelper extends ReactContextBaseJavaModule {
ReactApplicationContext reactContext;
Context context;
Intent intent;
public NetHelper(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
public String getName() {
return "WifiReceiver";
}
@ReactMethod
public void NetInfo() {
IntentFilter filter = new IntentFilter();
filter.addAction("android.net.wifi.WIFI_STATE_CHANGED");
filter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
WifiReceiver wifiReceiver = new WifiReceiver();
this.reactContext.registerReceiver(wifiReceiver, filter);
}
}`
and my wifi receiver class as:
`package com.check_net;
import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.util.Log; import android.widget.Toast;
public class WifiReceiver extends BroadcastReceiver { String TAG = getClass().getSimpleName(); private Context mContext;
@Override
public void onReceive(Context context, Intent intent) {
mContext = context;
if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = cm.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI &&
networkInfo.isConnected()) {
// Wifi is connected
WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
String ssid = wifiInfo.getSSID();
Log.e(TAG, " -- Wifi connected --- " + " SSID " + ssid );
Toast.makeText(context, " -- Wifi connected --- " + " SSID " + ssid , Toast.LENGTH_SHORT).show();
}
}
else if (intent.getAction().equalsIgnoreCase(WifiManager.WIFI_STATE_CHANGED_ACTION))
{
int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
if (wifiState == WifiManager.WIFI_STATE_DISABLED)
{
Toast.makeText(context, "Status changed", Toast.LENGTH_SHORT).show();
}
}
}
}`
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top GitHub Comments
Can you run
react-native info
and edit your issue to include these results under the React Native version: section?Thanks for submitting your issue. Can you take another look at your description and make sure the issue template has been filled in its entirety?
👉 Click here if you want to take another look at the Bug Report issue template.