问题
I have not too much experience with android services, the broadcastReceiver have some warning also WifiReceiver.java
uses or overrides a deprecated API. I search for this but couldn't find any solution, I don't know which one method is deprecated, I m not in touch too much with java and android
Here is error
cannot find symbol
registerReceiver(wifiReceiver,filter);
^
symbol: variable registerReceiver
My react Method is
@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();
registerReceiver(wifiReceiver,filter);
}
and broadcast receiver is
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();
}
}
}
}
getting this note also,
Note: Recompile with -Xlint:deprecation for details.
来源:https://stackoverflow.com/questions/58267236/network-native-module-android-not-working-in-react-native-progam-for-android-whi