Hi everyone!
I'm trying to make a simple, Intent-driven, "wifi status" app widget.
It simply displays a TextView with Wifi Status.
I overrided onReceive() method in AppWidgetProvider, so it could
trigger a "WifiManager.WIFI_STATE_CHANGED_ACTION".
Obviously i added the intentfilter in AndroidManifest.xml.
Then i created an "updateWidget()" method which updates the
RemoteViews on screen.
The problem is it doesn't work!
ACTUAL BEHAVIOUR:
The TextView only displays "DISABLING" (while Wifi is DISABLED) when
enabled, and then if I try to change wifi status, the TextView shows
ERROR (whick is widgettext default value that i set up).
Please Help!!!!
---------------------------------------------------------------------------------------------------------------
CODE OF APPWIDGETPROVIDER
package mx.widget.wifiwidget;
import android.app.Activity;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.SystemClock;
import android.util.Log;
import android.widget.RemoteViews;
public class WifiWidget extends AppWidgetProvider {
int wifistatus;
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
super.onReceive(context, intent);
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.wifiwidgetlayout);
String action = intent.getAction();
if (action.equals(WifiManager.WIFI_STATE_CHANGED_ACTION))
{
wifistatus =
intent.getIntExtra(WifiManager.WIFI_STATE_CHANGED_ACTION, 4);
}
updateWidget(context, wifistatus);
}
@Override
public void onUpdate(Context context, AppWidgetManager
appWidgetManager,
int[] appWidgetIds) {
// TODO Auto-generated method stub
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
public void updateWidget(Context context, int wifistatus){
String widgettext="ERROR";
AppWidgetManager manager =
AppWidgetManager.getInstance(context);
ComponentName thisWidget = new ComponentName(context,
WifiWidget.class);
int[] widgetIds = manager.getAppWidgetIds(thisWidget);
for (int widgetId : widgetIds) {
if (wifistatus==1){widgettext="DISABLED";}
else if (wifistatus==0){widgettext="DISABLING";}
else if (wifistatus==2){widgettext="ENABLING";}
else if (wifistatus==3){widgettext="ENABLED";}
RemoteViews views = new RemoteViews(context.getPackageName(),
R.layout.wifiwidgetlayout);
views.setTextViewText(R.id.TextView01,widgettext);
manager.updateAppWidget(widgetId, views);
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en