public static void getTagsAsync(final Context context, final GetTagsListener listener) {
    if (GCMRegistrar.isRegisteredOnServer(context) == false) return;

    Handler handler = new Handler(context.getMainLooper());
    handler.post(
        new Runnable() {
          public void run() {
            AsyncTask<Void, Void, Void> task =
                new WorkerTask(context) {
                  @Override
                  protected void doWork(Context context) {
                    Map<String, Object> tags;
                    try {
                      tags = DeviceFeature2_5.getTags(context);
                      listener.onTagsReceived(tags);
                    } catch (Exception e) {
                      listener.onError(e);
                    }
                  }
                };

            ExecutorHelper.executeAsyncTask(task);
          }
        });
  }
Exemplo n.º 2
0
  public void setupPushNotification() {

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    // registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      GCMRegistrar.register(this, ApplicationConstants.SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      }
    }
  }
Exemplo n.º 3
0
 public static boolean register(
     final Context context, final String regId, /* optional */ final String oldId) {
   Log.i(TAG, "registering device");
   String serverUrl = Secret.SERVER_REG_URL;
   Map<String, String> params = new HashMap<String, String>();
   params.put(P_REGID, regId);
   params.put(P_USER, PrefsHelper.getUser(context));
   params.put(P_PWD, PrefsHelper.getPwd(context));
   if (oldId != "") {
     params.put(P_OLDID, oldId);
   }
   long backoff = BACKOFF_MILLI_SECONDS + random.nextInt(1000);
   // Once GCM returns a registration id, we need to register it in the
   // app server. As the server might be down, we will retry it a couple
   // times.
   for (int i = 1; i <= MAX_ATTEMPTS; i++) {
     if (GCMRegistrar.isRegisteredOnServer(context)) {
       // AsyncTask finished meanwhile, return
       return false;
     }
     Log.d(TAG, "Attempt #" + i + " to register");
     try {
       String message = post(serverUrl, params);
       if (message.contains("Successfully added") || message.contains("already registered")) {
         GCMRegistrar.setRegisteredOnServer(context, true);
         GCMHelper.displayMessage(context, message);
         return true;
       } else {
         // dont backoff in case of a wrong password
         GCMHelper.displayMessage(context, message);
         return false;
       }
     } catch (IOException e) {
       Log.e(TAG, "Failed to register on attempt " + i, e);
       if (i == MAX_ATTEMPTS) {
         break;
       }
       try {
         Log.d(TAG, "Sleeping for " + backoff + " ms before retry");
         Thread.sleep(backoff);
       } catch (InterruptedException e1) {
         // Activity finished before we complete - exit.
         Log.d(TAG, "Thread interrupted: abort remaining retries!");
         Thread.currentThread().interrupt();
         return false;
       }
       // increase backoff exponentially
       backoff *= 2;
     }
   }
   String message = context.getString(R.string.server_register_error, MAX_ATTEMPTS);
   GCMHelper.displayMessage(context, message);
   return false;
 }
  @Override
  protected void onUnregistered(Context context, String registrationId) {
    // Log.i(TAG, "Device unregistered");
    CommonUtilities.displayMessage(context, "Device Unregistered");
    if (GCMRegistrar.isRegisteredOnServer(context)) {

    } else {
      // This callback results from the call to unregister made on
      // ServerUtilities when the registration to the server failed.
      // Log.i(TAG, "Ignoring unregister callback");
    }
  }
Exemplo n.º 5
0
  /**
   * Called after the device has been unregisterd from the GCM server. We we are registered on the
   * AirBop servers we should unregister from there as well.
   */
  @Override
  protected void onUnregistered(Context context, String registrationId) {

    Log.i(TAG, "Device unregistered");
    displayMessage(context, getString(R.string.gcm_unregistered));
    // If we are still registered with AirBop it is time to unregister
    if (GCMRegistrar.isRegisteredOnServer(context)) {
      AirBopServerUtilities.unregister(context, registrationId);
    } else {
      // This callback results from the call to unregister made on
      // ServerUtilities when the registration to the server failed.
      Log.i(TAG, "Ignoring unregister callback");
    }
  }
    @Override
    public void run() {
      final Context context = SuperManActivity_No_Pusher.this;
      CommonUtilities.UUID = UUID;
      // Make sure the device has the proper dependencies.
      GCMRegistrar.checkDevice(context);
      // while developing the app, then uncomment it when it's ready.
      GCMRegistrar.checkManifest(context);
      registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));
      final String regId = GCMRegistrar.getRegistrationId(context);
      Log.e(TAG, "regId: " + regId);
      if (regId.equals("")) {
        // Automatically registers application on startup.
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {
                GCMRegistrar.register(context, SENDER_ID);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      } else {
        // Device is already registered on GCM, check server.
        if (GCMRegistrar.isRegisteredOnServer(context)) {
          mRegisterTask =
              new AsyncTask<Void, Void, Void>() {

                @Override
                protected Void doInBackground(Void... params) {
                  ServerUtilities.register(context, regId);
                  return null;
                }

                @Override
                protected void onPostExecute(Void result) {
                  mRegisterTask = null;
                }
              };
          mRegisterTask.execute(null, null, null);
        }
      }
    }
  public static void sendLocation(final Context context, final Location location) {
    if (GCMRegistrar.isRegisteredOnServer(context) == false) return;

    Handler handler = new Handler(context.getMainLooper());
    handler.post(
        new Runnable() {
          public void run() {
            AsyncTask<Void, Void, Void> task =
                new WorkerTask(context) {
                  @Override
                  protected void doWork(Context context) {
                    try {
                      DeviceFeature2_5.getNearestZone(context, location);
                    } catch (Exception e) {
                      //								e.printStackTrace();
                    }
                  }
                };

            ExecutorHelper.executeAsyncTask(task);
          }
        });
  }
Exemplo n.º 8
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test_gcm);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showDialog(
          TestGCMActivity.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);
      // stop executing code by return
      return;
    }

    // Getting name, email from intent
    Intent i = getIntent();

    name = i.getStringExtra("name");
    email = i.getStringExtra("email");

    GCMRegistrar.checkDevice(this);
    // GCMRegistrar.checkManifest(this);

    // lblMessage = (TextView) findViewById(R.id.lblMessage);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                ServerUtilities.register(context, name, email, regId);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_screen);

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          MainScreenActivity.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);
      // stop executing code by return
      return;
    }

    Intent i = getIntent();
    name = i.getStringExtra("name");
    email = i.getStringExtra("email");

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    lblMessage = (TextView) findViewById(R.id.lblMessage);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(
                getApplicationContext(), "Registration with server is verified!", Toast.LENGTH_LONG)
            .show();
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {
              @Override
              protected Void doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                ServerUtilities.register(context, name, email, regId);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }

    File folder = new File(Environment.getExternalStorageDirectory() + "/itmpdf");

    if (!folder.exists()) {
      success = folder.mkdirs();
      if (success) {
        Log.i("directory created", "directory created");
      } else {
        Log.i("directory not created", "directory not created");
      }
    } else {
      Log.i("Directorylog", "Directory ALready Exists");
    }

    // Buttons
    btnViewResults = (ImageButton) findViewById(R.id.btnViewResults);
    btnViewEvents = (ImageButton) findViewById(R.id.btnViewNotices);
    btnViewAnnounce = (ImageButton) findViewById(R.id.btnViewAnnounce);
    btntt = (ImageButton) findViewById(R.id.btntt);
    btntalky = (ImageButton) findViewById(R.id.btntalky);
    btnabt = (ImageButton) findViewById(R.id.btnabt);
    dwnmanager = (ImageButton) findViewById(R.id.dwnmanager);
    ImageButton ratemyapp = (ImageButton) findViewById(R.id.ratemyapp);

    btnViewResults.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllResultsActivity.class);
            startActivity(i);
          }
        });

    btnViewEvents.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllEventsActivity.class);
            startActivity(i);
          }
        });

    btnViewAnnounce.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllAnnActivity.class);
            startActivity(i);
          }
        });

    btntt.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), TimetableActivity.class);
            startActivity(i);
          }
        });

    btntalky.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), TalkyLaunchActivity.class);
            startActivity(i);
          }
        });

    btnabt.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), AllAbtActivity.class);
            startActivity(i);
          }
        });

    dwnmanager.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Intent i = new Intent(getApplicationContext(), ScanPdf.class);
            startActivity(i);
          }
        });

    ratemyapp.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Uri uri = Uri.parse("market://details?id=" + getPackageName());
            Log.i("URI", uri.toString());
            Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
            try {
              startActivity(goToMarket);
            } catch (ActivityNotFoundException e) {
              Toast.makeText(getBaseContext(), "Couldn't launch the market", Toast.LENGTH_LONG)
                  .show();
            }
          }
        });
  }
Exemplo n.º 10
0
  public static Map<String, Object> getTagsSync(final Context context) {
    if (GCMRegistrar.isRegisteredOnServer(context) == false) return null;

    return DeviceFeature2_5.getTags(context);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gcm);

    cd = new ConnectionDetector(getApplicationContext());

    if (!cd.isConnectingToInternet()) {

      alert.showAlertDialog(
          ActivityGCM.this,
          "Internet Connection Error",
          "Please connect to working Internet connection",
          false);

      return;
    }

    Intent i = getIntent();

    name = i.getStringExtra("name");
    email = i.getStringExtra("email");

    GCMRegistrar.checkDevice(this);

    GCMRegistrar.checkManifest(this);

    lblMessage = (TextView) findViewById(R.id.lblMessage);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));

    final String regId = GCMRegistrar.getRegistrationId(this);

    if (regId.equals("")) {

      GCMRegistrar.register(this, SENDER_ID);
    } else {

      if (GCMRegistrar.isRegisteredOnServer(this)) {

        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      } else {

        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {

                ServerUtilities.register(context, name, email, regId);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
  }
Exemplo n.º 12
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main_menu);
    login = getSharedPreferences("mec-data", 0);
    Log.d("Shr-Login", "username: "******"username", ""));
    Log.d("Shr-Login", "password: "******"password", ""));
    // GCM
    checkNotNull(SERVER_URL, "SERVER_URL");
    checkNotNull(SENDER_ID, "SENDER_ID");
    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);
    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);
    // setContentView(R.layout.main_menu);
    // hr = (TextView) findViewById(R.id.Hari);
    registerReceiver(mHandleMessageReceiver, new IntentFilter(DISPLAY_MESSAGE_ACTION));
    final String regId = GCMRegistrar.getRegistrationId(this);

    if (regId.equals("")) {
      // Automatically registers application on startup.
      GCMRegistrar.register(getApplicationContext(), SENDER_ID);
    } else {
      // Device is already registered on GCM, check server.
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        // hr.append(getString(R.string.already_registered) + "\n");
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {
              private ProgressDialog pDialog;
              protected Context applicationContext;

              @Override
              protected void onPreExecute() {
                super.onPreExecute();
                pDialog = new ProgressDialog(MainMenu.this);
                pDialog.setMessage("Registering device. Please wait...");
                pDialog.setIndeterminate(false);
                pDialog.setCancelable(false);
                pDialog.show();
              }

              @Override
              protected Void doInBackground(Void... params) {
                boolean registered = ServerUtilities.register(context, regId);
                // At this point all attempts to register with the app
                // server failed, so we need to unregister the device
                // from GCM - the app will try to register again when
                // it is restarted. Note that GCM will send an
                // unregistered callback upon completion, but
                // GCMIntentService.onUnregistered() will ignore it.
                if (!registered) {
                  GCMRegistrar.unregister(context);
                }
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
                pDialog.dismiss();
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
    // END GCM
    View tugasButton = findViewById(R.id.tugas_button);
    tugasButton.setOnClickListener(this);
    View logoutButton = findViewById(R.id.logout_button);
    logoutButton.setOnClickListener(this);
    View exitButton = findViewById(R.id.exit_button);
    exitButton.setOnClickListener(this);
    /*View jadwalButton=findViewById(R.id.jadwal_button);
    jadwalButton.setOnClickListener(this);

    bv = (TextView) findViewById(R.id.jadwal_button);
    hr = (TextView) findViewById(R.id.Hari);*/
    // registerForContextMenu((View) findViewById(R.id.jadwal_button));
  }
Exemplo n.º 13
0
  /**
   * Register the username, email, and device ID information in the database.
   *
   * @param name Name of the user
   * @param email Email of the user
   */
  void register(final String name, final String email) {

    cd = new ConnectionDetector(getApplicationContext());

    // Check if Internet present
    if (!cd.isConnectingToInternet()) {
      // Internet Connection is not present
      alert.showAlertDialog(
          "Internet Connection Error", "Please connect to working Internet connection", false);
      // stop executing code by return
      // return;
    }

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);

    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);

    // lblMessage = (TextView) findViewById(R.id.lblMessage);

    // registerReceiver(mHandleMessageReceiver, new IntentFilter(
    // DISPLAY_MESSAGE_ACTION));

    // Get GCM registration id
    final String regId = GCMRegistrar.getRegistrationId(this);

    // Check if regid already presents
    if (regId.equals("")) {
      // Registration is not present, register now with GCM
      Log.i(TAG, "regId is empty");
      GCMRegistrar.register(this, SENDER_ID);
    } else {
      // Device is already registered on GCM
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        Toast.makeText(getApplicationContext(), "Already registered with GCM", Toast.LENGTH_LONG)
            .show();
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Boolean>() {
              @Override
              protected Boolean doInBackground(Void... params) {
                // Register on our server
                // On server creates a new user
                Log.i(TAG, "Calling register from AsyncTask in RegisterActivity");
                boolean res = ServerUtilities.register(context, name, email, regId);

                Log.d(TAG, "Got here");
                if (res) {
                  Log.d(TAG, "successful registration");
                  Intent homeScreen =
                      new Intent(getApplicationContext(), LocalizationActivity.class);
                  startActivity(homeScreen);

                  return true;
                } else {
                  Log.d(TAG, "unsuccessful registration");
                }
                return false;
              }

              @Override
              protected void onPostExecute(Boolean result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }
  }
Exemplo n.º 14
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Make sure the device has the proper dependencies.
    GCMRegistrar.checkDevice(this);
    // Make sure the manifest was properly set - comment out this line
    // while developing the app, then uncomment it when it's ready.
    GCMRegistrar.checkManifest(this);
    setContentView(R.layout.activity_main);

    registerReceiver(mHandleMessageReceiver, new IntentFilter(EXTRA_MESSAGE));
    registrationID = GCMRegistrar.getRegistrationId(this);
    System.out.println("GCM Reg Id is = " + registrationID);
    if (registrationID.equals("")) {
      // Automatically registers application on startup.
      System.out.println("2 GCM Reg Id is = " + registrationID);
      GCMRegistrar.register(this, SENDER_ID);
      System.out.println("3 GCM Reg Id is = " + registrationID);
    } else {
      // Device is already registered on GCM, check server.
      if (GCMRegistrar.isRegisteredOnServer(this)) {
        // Skips registration.
        System.out.println(getString(R.string.already_registered) + "\n");
      } else {
        // Try to register again, but not in the UI thread.
        // It's also necessary to cancel the thread onDestroy(),
        // hence the use of AsyncTask instead of a raw thread.
        final Context context = this;
        mRegisterTask =
            new AsyncTask<Void, Void, Void>() {

              @Override
              protected Void doInBackground(Void... params) {
                ServerUtilities.register(context, registrationID);
                return null;
              }

              @Override
              protected void onPostExecute(Void result) {
                mRegisterTask = null;
              }
            };
        mRegisterTask.execute(null, null, null);
      }
    }

    /*-----------------------------------------------------------------
     *
     *    Bottom Button Bar Page Switching Function
     *
     *-----------------------------------------------------------------*/

    Button logIn = (Button) findViewById(R.id.login);
    logIn.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), LoginActivity.class);
            startActivityForResult(myIntent, 0);
          }
        });

    Button accountLogIn = (Button) findViewById(R.id.account_login);
    accountLogIn.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), LoginActivity.class);
            startActivityForResult(myIntent, 0);
          }
        });
    Button homePage = (Button) findViewById(R.id.home_page);
    homePage.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Intent myIntent = new Intent(view.getContext(), MainActivity.class);
            startActivityForResult(myIntent, 0);
          }
        });

    testQuery();
  }