Пример #1
1
 /**
  * Register the device to Google Cloud Messaging service or return registration id if it's already
  * registered.
  *
  * @return registration id or empty string if it's not registered.
  */
 private static String gcmRegisterIfNot(Context context) {
   String regId = "";
   try {
     GCMRegistrar.checkDevice(context);
     GCMRegistrar.checkManifest(context);
     regId = GCMRegistrar.getRegistrationId(context);
     String gcmId = BuildConfig.GCM_ID;
     if (gcmId != null && TextUtils.isEmpty(regId)) {
       GCMRegistrar.register(context, gcmId);
     }
   } catch (UnsupportedOperationException e) {
     // GCMRegistrar.checkDevice throws an UnsupportedOperationException if the device
     // doesn't support GCM (ie. non-google Android)
     AppLog.e(T.NOTIFS, "Device doesn't support GCM: " + e.getMessage());
   } catch (IllegalStateException e) {
     // GCMRegistrar.checkManifest or GCMRegistrar.register throws an IllegalStateException if
     // Manifest
     // configuration is incorrect (missing a permission for instance) or if GCM dependencies are
     // missing
     AppLog.e(
         T.NOTIFS,
         "APK (manifest error or dependency missing) doesn't support GCM: " + e.getMessage());
   } catch (Exception e) {
     // SecurityException can happen on some devices without Google services (these devices
     // probably strip
     // the AndroidManifest.xml and remove unsupported permissions).
     AppLog.e(T.NOTIFS, e);
   }
   return regId;
 }
Пример #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();
      }
    }
  }
 private void registerDevice() {
   if (mSenderID == null) {
     throw new IllegalArgumentException(
         "sender ID is required in order to register this device for push notifications. You must specify the senderId in the ApplicationManifest or when calling the JavaScript API.");
   }
   GCMRegistrar.register(mContext, mSenderID);
 }
Пример #4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tabs);

    preferenciasFragment = new PreferenciasFragment();
    preferenciasFragment.setPreferencesListener(this);

    inicioFragment = new InicioFragment();
    inicioFragment.setInicioLoadedListener(this);

    crearMapFragment();

    ArrayList<Fragment> fragments = new ArrayList<Fragment>();
    fragments.add(preferenciasFragment);
    fragments.add(inicioFragment);
    if (myMapFragment != null) {
      fragments.add(myMapFragment);
    }

    mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager(), fragments);
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);

    // mViewPager.setCurrentItem(1);

    mViewPager.setOnPageChangeListener(this);

    registroGCM();

    GCMRegistrar.checkDevice(this);
    GCMRegistrar.register(this, "834884443249");

    servicioGuardarPosicion();
  }
Пример #5
0
 private void registerForPush() {
   GCMRegistrar.checkDevice(this);
   GCMRegistrar.checkManifest(this);
   REG_ID = GCMRegistrar.getRegistrationId(this);
   if (REG_ID.equals("")) {
     GCMRegistrar.register(this, "336168193323");
   } else {
     System.out.println("Already Registered");
   }
 }
Пример #6
0
  @Override
  public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

    boolean result = false;

    Log.v(TAG, "execute: action=" + action);

    if (REGISTER.equals(action)) {

      Log.v(TAG, "execute: data=" + data.toString());

      try {
        JSONObject jo = data.getJSONObject(0);

        gWebView = this.webView;
        Log.v(TAG, "execute: jo=" + jo.toString());

        gECB = (String) jo.get("ecb");
        gSenderID = (String) jo.get("senderID");

        Log.v(TAG, "execute: ECB=" + gECB + " senderID=" + gSenderID);

        GCMRegistrar.register(getApplicationContext(), gSenderID);
        result = true;
        callbackContext.success();
      } catch (JSONException e) {
        Log.e(TAG, "execute: Got JSON Exception " + e.getMessage());
        result = false;
        callbackContext.error(e.getMessage());
      }

      if (gCachedExtras != null) {
        Log.v(TAG, "sending cached extras");
        sendExtras(gCachedExtras);
        gCachedExtras = null;
      }

    } else if (UNREGISTER.equals(action)) {

      GCMRegistrar.unregister(getApplicationContext());

      Log.v(TAG, "UNREGISTER");
      result = true;
      callbackContext.success();
    } else {
      result = false;
      Log.e(TAG, "Invalid action : " + action);
      callbackContext.error("Invalid action : " + action);
    }

    return result;
  }
Пример #7
0
  private void initGCM() {
    try {
      // Make sure the device has the proper dependencies.
      GCMRegistrar.checkDevice(this);

      final String regId = GCMRegistrar.getRegistrationId(this);
      if (regId.equals("")) {
        // Automatically registers application on startup.
        GCMRegistrar.register(this, SENDER_ID);
      }
    } catch (Exception e) {
      EasyTracker.getTracker().trackException("cannot init GCM", e, false);
    }
  }
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Register application for Google Cloud Messaging
    GCMRegistrar.checkDevice(this);
    GCMRegistrar.checkManifest(this); // Remove in production
    final String regId = GCMRegistrar.getRegistrationId(this);
    if (regId.equals("")) {
      GCMRegistrar.register(this, Utils.SENDER_ID);
    } else {
      Log.v(TAG, "Already registered");
    }

    setContentView(R.layout.messages);
  }
 public void registerPushAccount() {
   GCMRegistrar.checkDevice(this);
   GCMRegistrar.checkManifest(this);
   if (GCMRegistrar.isRegistered(this)) {
     Log.d("info", GCMRegistrar.getRegistrationId(this));
   }
   String regId = GCMRegistrar.getRegistrationId(this);
   if (regId.equals("")) {
     GCMRegistrar.register(this, AppConstants.PUSH_NOTIFICATION_KEY);
     Log.d("info", GCMRegistrar.getRegistrationId(this));
     regId = GCMRegistrar.getRegistrationId(this);
   } else {
     Log.d("info", "already registered as" + regId);
   }
   prefsEditor.putString(AppConstants.PREFPUSHREGISTRATIONID, regId);
   Log.d("info", regId);
   prefsEditor.commit();
 }
  protected void registerGCM() {
    try {
      String senderId = app.getAppJsonSetting().getSenderId();
      // GCM registration process
      GCMRegistrar.checkDevice(this);
      GCMRegistrar.checkManifest(this);
      final String regId = GCMRegistrar.getRegistrationId(this);
      if (regId.equals("")) {
        GCMRegistrar.register(this, senderId);
      } else {
        ((MonacaApplication) getApplication()).sendGCMRegisterIdToAppAPI(regId);
      }

    } catch (Exception e) {
      MyLog.d(TAG, "this device or application does not support GCM");
      e.printStackTrace();
    }
  }
Пример #11
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

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

    setContentView(R.layout.main);
    tv_sender_nickname = (TextView) findViewById(R.id.sender_nickname);
    tv_recipients_nickname = (TextView) findViewById(R.id.recipients_nickname);
    tv_message = (TextView) findViewById(R.id.message);
    btn_read_more_button = (Button) findViewById(R.id.read_more_button);

    final String regId = GCMRegistrar.getRegistrationId(this);
    Log.i(debugAppTag, "registration id ==  " + regId);

    if (regId.equals("")) {
      GCMRegistrar.register(this, ApplicationContext.getSenderID());
    } else {
      Log.v(debugAppTag, "Already registered");
    }
  }
Пример #12
0
 /**
  * Register the device for GCM.
  *
  * @param mContext the activity's context.
  */
 public static void register(Context mContext) {
   GCMRegistrar.checkDevice(mContext);
   GCMRegistrar.checkManifest(mContext);
   GCMRegistrar.register(mContext, PROJECT_ID);
 }
  public void init(Context cnt, String tkn, String appid, String ServerUrl)
      throws CommunicatorConnectorException {
    mContext = cnt.getApplicationContext();
    mUserAuthToken = tkn;

    mAppId = appid;
    mServerUrl = ServerUrl;

    CommunicatorConnector mConnector = null;
    try {
      mConnector = new CommunicatorConnector(mServerUrl, mAppId);

      String regId = "";
      // This registerClient() method checks the current device,
      // checks the
      // manifest for the appropriate rights, and then retrieves a
      // registration id
      // from the GCM cloud. If there is no registration id,
      // GCMRegistrar will
      // register this device for the specified project, which will
      // return a
      // registration id.
      // Check that the device supports GCM (should be in a try /
      // catch)
      GCMRegistrar.checkDevice(mContext);

      // Check the manifest to be sure this app has all the
      // required
      // permissions.
      GCMRegistrar.checkManifest(mContext);

      // Get the existing registration id, if it exists.
      regId = GCMRegistrar.getRegistrationId(mContext);

      if (regId.equals("")) {
        if (mConnector != null) {
          Map<String, Object> mapKey =
              mConnector.requestPublicConfigurationToPush("core.mobility", mUserAuthToken);

          // find senderid
          String senderid = String.valueOf(mapKey.get("GCM_SENDER_ID"));
          // register this device for this project
          //					senderid= "220741898329";
          GCMRegistrar.register(mContext, senderid);
          regId = GCMRegistrar.getRegistrationId(mContext);
          if (regId != null && regId.length() > 0) {
            UserSignature signUserSignature = new UserSignature();
            signUserSignature.setAppName("core.mobility");
            signUserSignature.setRegistrationId(regId);
            mConnector.registerUserToPush(signUserSignature, "core.mobility", mUserAuthToken);
          }
        }
      } else {
        // Already registered;
      }

      Log.i("GCM_REGID:", regId);
    } catch (Exception e) {
      Log.e(TAG, e.toString());
    }
  }
Пример #14
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));
  }
Пример #15
0
  @Override
  public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

    boolean result = false;

    Log.v(LOG_TAG, "execute: action=" + action);

    if (INITIALIZE.equals(action)) {
      pushContext = callbackContext;
      JSONObject jo = null;

      Log.v(LOG_TAG, "execute: data=" + data.toString());

      try {
        jo = data.getJSONObject(0).getJSONObject("android");

        gWebView = this.webView;
        Log.v(LOG_TAG, "execute: jo=" + jo.toString());

        gSenderID = jo.getString("senderID");

        Log.v(LOG_TAG, "execute: senderID=" + gSenderID);

        // https://github.com/t-nonque/phonegap-plugin-push/commit/c54439b721741c77b7b4de38af690ee6a25d88a4
        boolean registered = GCMRegistrar.isRegistered(getApplicationContext());
        if (!registered) {
          GCMRegistrar.register(getApplicationContext(), gSenderID);
        }
        result = true;
      } catch (JSONException e) {
        Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
        result = false;
        callbackContext.error(e.getMessage());
      }

      if (jo != null) {
        SharedPreferences sharedPref =
            getApplicationContext()
                .getSharedPreferences(COM_ADOBE_PHONEGAP_PUSH, Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPref.edit();
        try {
          editor.putString("icon", jo.getString("icon"));
        } catch (JSONException e) {
          Log.d(LOG_TAG, "no icon option");
        }
        try {
          editor.putString("iconColor", jo.getString("iconColor"));
        } catch (JSONException e) {
          Log.d(LOG_TAG, "no iconColor option");
        }
        editor.putBoolean("sound", jo.optBoolean("sound", true));
        editor.putBoolean("vibrate", jo.optBoolean("vibrate", true));
        editor.putBoolean("clearNotifications", jo.optBoolean("clearNotifications", true));
        editor.commit();
      }

      if (gCachedExtras != null) {
        Log.v(LOG_TAG, "sending cached extras");
        sendExtras(gCachedExtras);
        gCachedExtras = null;
      }

    } else if (UNREGISTER.equals(action)) {

      GCMRegistrar.unregister(getApplicationContext());

      Log.v(LOG_TAG, "UNREGISTER");
      result = true;
      callbackContext.success();
    } else {
      result = false;
      Log.e(LOG_TAG, "Invalid action : " + action);
      callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
    }

    return result;
  }
Пример #16
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);
      }
    }
  }
Пример #17
0
  @Override
  public boolean execute(String action, JSONArray data, CallbackContext callbackContext) {

    boolean result = false;

    Log.v(TAG, "execute: action=" + action);

    if (REGISTER.equals(action)) {

      Log.v(TAG, "execute: data=" + data.toString());

      try {
        JSONObject jo = data.getJSONObject(0);

        gWebView = this.webView;
        Log.v(TAG, "execute: jo=" + jo.toString());

        gECB = (String) jo.get("ecb");
        gSenderID = (String) jo.get("senderID");
        String gDeviceId = (String) jo.get("deviceID");
        String gDeviceIsReg = (String) jo.get("deviceIsReg");
        Log.v(TAG, "execute: ECB=" + gECB + " senderID=" + gSenderID);

        // 미등록 혹은 임시등록 이 아닌 경우  는 기등록이므로 레지스터 안함
        if (gDeviceId != null && !gDeviceId.equals("null") && !gDeviceId.equals("")) {
          if (gDeviceIsReg.equals("true")) {
            Log.v(TAG, "디바이스 푸쉬 아이디 기등록  = " + gDeviceId);
            callbackContext.success();
            return true; // 이미 등록된 디바이스 - 등록 중지
          }
        }
        Log.v(TAG, "디바이스 푸쉬 아이디 미등록 -> 등록시작");

        GCMRegistrar.register(getApplicationContext(), gSenderID);
        result = true;
        callbackContext.success();
      } catch (JSONException e) {
        Log.e(TAG, "execute: Got JSON Exception " + e.getMessage());
        result = false;
        callbackContext.error(e.getMessage());
      }

      if (gCachedExtras != null) {
        Log.v(TAG, "sending cached extras");
        sendExtras(gCachedExtras);
        gCachedExtras = null;
      }

    } else if (UNREGISTER.equals(action)) {

      GCMRegistrar.unregister(getApplicationContext());

      Log.v(TAG, "UNREGISTER");
      result = true;
      callbackContext.success();
    } else {
      result = false;
      Log.e(TAG, "Invalid action : " + action);
      callbackContext.error("Invalid action : " + action);
    }

    return result;
  }
  @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();
            }
          }
        });
  }
  @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);
      }
    }
  }
Пример #20
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);
      }
    }
  }
Пример #21
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();
  }