0

i have widget that i need to show IP

i have this for show IP

public ShowIP()
{
try
        {
         WifiManager myWifiManager = (WifiManager)getSystemService(Context.WIFI_SERVICE);
            WifiInfo myWifiInfo = myWifiManager.getConnectionInfo();

            int myIp = Math.abs(myWifiInfo.getIpAddress());

            int intMyIp3 = myIp/0x1000000;
            int intMyIp3mod = myIp%0x1000000;

            int intMyIp2 = intMyIp3mod/0x10000;
            int intMyIp2mod = intMyIp3mod%0x10000;

            int intMyIp1 = intMyIp2mod/0x100;
            int intMyIp0 = intMyIp2mod%0x100;

            IP = String.valueOf(intMyIp0) + "." + String.valueOf(intMyIp1) + "." + String.valueOf(intMyIp2) + "." + String.valueOf(intMyIp3); //===V
        }
        catch (Exception ex)
        {
            IP = "Error Network";
        }
    }

in my widget i try to call ShowIP() like this:

public class HelloWidget extends AppWidgetProvider {

    public String IP;

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
    }

    private class MyTime extends TimerTask {
        RemoteViews remoteViews;
        AppWidgetManager appWidgetManager;
        ComponentName thisWidget;
        DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM, Locale.getDefault());

    public MyTime(Context context, AppWidgetManager appWidgetManager) {
        this.appWidgetManager = appWidgetManager;
        remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
        thisWidget = new ComponentName(context, HelloWidget.class);
    }

    @Override
    public void run() {
                ShowIP();
        remoteViews.setTextViewText(R.id.widget_textview, IP);
        appWidgetManager.updateAppWidget(thisWidget, remoteViews);
    }


    @SuppressWarnings("unused")
    public  void pushWidgetUpdate(Context context, RemoteViews remoteViews) {
        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
    }

    }

}

the problem that getSystemService Unidentified word

how to to it ?

thanks

4

0 回答 0