Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code work when App is an Background(minimize state)but not working when App is an kill state after bridging with react native #26780

Closed
MajidAziz3 opened this issue Oct 9, 2019 · 2 comments
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@MajidAziz3
Copy link

MajidAziz3 commented Oct 9, 2019

Service 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(R) Core(TM) 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,

NetHelper class

`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:

`
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();
    }

}

}`

@MajidAziz3 MajidAziz3 added the Bug label Oct 9, 2019
@stale
Copy link

stale bot commented Jan 7, 2020

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

@stale stale bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Jan 7, 2020
@stale
Copy link

stale bot commented Jan 14, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

@stale stale bot closed this as completed Jan 14, 2020
@facebook facebook locked as resolved and limited conversation to collaborators Jan 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

1 participant