question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 issue

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® 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:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
react-native-botcommented, Oct 9, 2019

Can you run react-native info and edit your issue to include these results under the React Native version: section?

If you believe this information is irrelevant to the reported issue, you may write `[skip envinfo]` alongside an explanation in your Environment: section.</detail>
1reaction
react-native-botcommented, Oct 9, 2019

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Code work when App is an Background(minimize state)but not ...
Code work when App is an Background(minimize state)but not working when App is an kill state after bridging with react native #26780.
Read more >
Background processing being killed after seconds when ...
I'm using react-native-callkeep to show the user the default IOS call screen when receiving a call (On background and foreground), and I'm using ......
Read more >
Overcoming single-threaded limitations in React Native
In this blog post, we'll take a look at certain features that limit React Native's performance and how we can reduce their effects...
Read more >
Multi-window support - Android Developers
Multi-window mode enables multiple apps to share the same screen simultaneously. Apps can be side by side or one above the other (split-screen...
Read more >
Contentsquare React Native Integration
Open up a terminal window and navigate to the folder where your application is stored. First, find the latest version of the bridge...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found