Android Open Source - VirginMobileMinutesChecker Update Service

From Project

Back to project page VirginMobileMinutesChecker.


The source code is released under:

Copyright 2011 Jay Goel. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Red...

If you think the Android project VirginMobileMinutesChecker listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jaygoel.virginminuteschecker;
/* w ww. j  a v a2  s .c o m*/
import android.appwidget.AppWidgetManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.RemoteViews;

public class UpdateService extends Service {
  private static final String TAG= "DEBUG";
  public static final String EVENT= "com.jaygoel.virginminuteschecker.call_trigger.UpdateService.Action";
  private Context saved_context;
    private final PhoneStateListener phoneStateListener = new PhoneStateListener(){
        public void onCallStateChanged(int state, String incomingNumber)
            Log.d(TAG, "in oncallstatechanged");
                String callState = "UNKNOWN";
                        case TelephonyManager.CALL_STATE_IDLE:          callState = "IDLE"; break;
                        case TelephonyManager.CALL_STATE_RINGING:       callState = "Ringing (" + incomingNumber + ")"; break;
                        case TelephonyManager.CALL_STATE_OFFHOOK:       callState = "Offhook"; break;
                if (callState=="IDLE")
                  Log.d(TAG, "does this shit work?");

                super.onCallStateChanged(state, incomingNumber);
    public void onCreate() {
      Log.d(TAG, "in create");
    saved_context = this;
        TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        tm.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);

    public static void update(Context context) {
      Log.d(TAG, "in update");
      AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        RemoteViews remoteViews;
        ComponentName widget;

        remoteViews = new RemoteViews( context.getPackageName(), R.layout.widget );
        widget = new ComponentName( context, Widget.class );
      SharedPreferences settings = context.getSharedPreferences("loginInfo", 0);
      String username = settings.getString("username", "u");
      String password = settings.getString("password", "p");

      SharedPreferences cache = context.getSharedPreferences("cache", 0);

      String minutes;
      if (username.equals("u") || password.equals("p")) {
          minutes= "Not Logged In";
          Log.d(TAG, "Not Logged In");
      } else {
          String html= WebsiteScraper.fetchScreen(username, password);
          Log.d(TAG, html);
          IVMCScraper scraper= new ReferenceScraper();
          if (scraper.isValid(html)) {
        Log.d(TAG, "valid");
        minutes= scraper.getMinutesUsed(html);
        Log.d(TAG, minutes);

        SharedPreferences.Editor cedit= cache.edit();
        cedit.putString("minutes", minutes);
          } else {
        minutes= "Problem Loading Page";
        remoteViews.setTextViewText(, "Minutes Used: " + minutes);
        appWidgetManager.updateAppWidget( widget, remoteViews );
  public IBinder onBind(Intent arg0) {
      Log.d(TAG, "in onbind (shouldn't happen)");
    // TODO Auto-generated method stub
    return null;

Java Source Code List