There are two classes in my application, one is InternetActivity, which only extends the Activity and sets the contentview to main. and MyClass, which extends the broadcast receiver.
I have 2 TextViews and 2 ImageViews from WIFI and GPRS in the main.xml file. When changes in relationships occur, the Broadcast receiver receives the call both according to what is turned on and that I do not want to set the visibility of TextView and ImageView. But it shows only images, not changes. here is the file MyClass.java. How can i do this?
public class MyClass extends BroadcastReceiver {
private static ImageView wifi_image, gprs_image;
private static TextView wifi_text, gprs_text;
@Override
public void onReceive(Context context, Intent intent) {
Log.i("IntrntActivity", "Broadcast message receivved");
LinearLayout layout = new LinearLayout(context);
LinearLayout.LayoutParams params = new LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
View view = View.inflate(context, R.layout.main, layout);
wifi_image = (ImageView) view.findViewById(R.id.wifi_image);
gprs_image = (ImageView) view.findViewById(R.id.gprs_image);
wifi_text = (TextView) view.findViewById(R.id.wifi_text);
gprs_text = (TextView) view.findViewById(R.id.gprs_text);
wifi_image.setVisibility(View.GONE);
wifi_text.setVisibility(View.GONE);
gprs_image.setVisibility(View.GONE);
gprs_text.setVisibility(View.GONE);
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(context.CONNECTIVITY_SERVICE);
NetworkInfo WIFI = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
NetworkInfo Mobile = cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
if (!WIFI.isConnected() && WIFI.isAvailable()) {
Toast.makeText(context, "WIFI is available but not connected",
Toast.LENGTH_LONG).show();
}
if (cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isAvailable()) {
wifi_image.setVisibility(View.VISIBLE);
wifi_text.setVisibility(View.VISIBLE);
}
if (Mobile.isConnected()) {
gprs_image.setVisibility(View.VISIBLE);
gprs_text.setVisibility(View.VISIBLE);
Log.i("IntrntActivity", "Mobile isConnected");
}
if (!Mobile.isConnected()) {
gprs_image.setVisibility(View.GONE);
gprs_text.setVisibility(View.GONE);
Log.i("IntrntActivity", "Mobile is Not Connected");
}
}
}
P.S: Mobile.isConnected() !Mobile.isConnected() , . ? setContentView () ?