예제 #1
0
  protected void sendPushNotifications() {

    ParseQuery<ParseInstallation> query = ParseInstallation.getQuery();
    query.whereContainedIn(ParseConstants.KEY_USER_ID, getRecipientIds());

    ParsePush push = new ParsePush();
    push.setQuery(query);
    push.setMessage("You have a new message from " + ParseUser.getCurrentUser().getUsername());
    push.sendInBackground();
  }
예제 #2
0
  private static void sendNotification() {
    JSONObject data = null;
    try {
      data = new JSONObject("{\"action\": \"com.cs160.customjob.commons.chat.UPDATE_MESSAGES\"}");
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    ParsePush push = new ParsePush();
    push.setChannel("UpdateChatMessages");
    push.setData(data);
    push.sendInBackground();
  }
  @Override
  public void onCreate() {
    super.onCreate();
    // Register your parse models here
    ParseObject.registerSubclass(Address.class);
    ParseObject.registerSubclass(Gym.class);
    ParseObject.registerSubclass(Message.class);
    ParseObject.registerSubclass(SimpleUser.class);
    ParseObject.registerSubclass(Trainer.class);
    ParseObject.registerSubclass(Review.class);
    ParseObject.registerSubclass(TrainerSlots.class);
    ParseObject.registerSubclass(BlockedSlots.class);
    Parse.enableLocalDatastore(this);
    Parse.initialize(this, APPLICATION_ID, CLIENT_KEY);

    ParsePush.subscribeInBackground(
        "",
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            if (e == null) {
              Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
              PushService.setDefaultPushCallback(
                  getBaseContext(),
                  ChatActivity.class); // change the class where u want to go after clicking on noti
              ParseInstallation.getCurrentInstallation().saveInBackground();
            } else {
              Log.e("com.parse.push", "failed to subscribe for push", e);
            }
          }
        });

    FacebookSdk.sdkInitialize(getApplicationContext());
  }
  public static boolean sendBindInvitationById(String Id) {

    ParseInstallation.getCurrentInstallation().saveInBackground();

    // Associate the device with a user
    ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    installation.put("pushToId", Id); // Should not be objectId!
    // which already have in Installation table
    try {
      installation.save();
    } catch (ParseException e) {
      e.printStackTrace();
      Log.d("push", e.toString());
    }

    ParseQuery pushQuery = ParseInstallation.getQuery();
    pushQuery.whereEqualTo("pushToId", Id);

    // TODO still needs to have some extra info needs to be saved in this push

    // Send push notification to query
    ParsePush push = new ParsePush();
    //        String json = new ""
    //        JSONObject jsonObject = new JSONObject()
    //        push.setData();
    push.setQuery(pushQuery); // Set our Installation query
    push.setMessage("Binding Invitation from " + ParseUser.getCurrentUser().getUsername());
    push.sendInBackground(
        new SendCallback() {
          @Override
          public void done(ParseException e) {
            if (e == null) {
              Log.d("push", "The push campaign has been created.");
            } else {
              Log.d("push", "Error sending push:" + e.getMessage());
            }
          }
        });
    return true;
  }
예제 #5
0
  public static void removeCommunityFromCurrentUser(final ParseObject community) {
    ParseUser user = ParseUser.getCurrentUser();
    ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION);
    relation.remove(community);
    user.saveInBackground();

    ParseRelation<ParseObject> communityUsers =
        community.getRelation(Common.OBJECT_COMMUNITY_USERS);
    communityUsers.remove(user);
    community.saveInBackground();

    String channel = "community_" + community.getObjectId();
    ParsePush.unsubscribeInBackground(channel);
  }
예제 #6
0
  public static void addCommunityToUser(final ParseObject community) {
    ParseUser user = ParseUser.getCurrentUser();
    ParseRelation<ParseObject> relation = user.getRelation(Common.OBJECT_USER_COMMUNITY_RELATION);
    relation.add(community);
    user.saveInBackground(
        new SaveCallback() {
          @Override
          public void done(ParseException e) {
            getUserCommunity(ParseUser.getCurrentUser());
          }
        });

    ParseRelation<ParseObject> communityUsers =
        community.getRelation(Common.OBJECT_COMMUNITY_USERS);
    communityUsers.add(user);
    community.saveInBackground();

    String channel = "community_" + community.getObjectId();
    ParsePush.subscribeInBackground(channel);
  }
  public void pushNotification(View view) {

    Button pushButton = (Button) findViewById(R.id.sendPushButton);

    final ProgressBar loading = (ProgressBar) findViewById(R.id.progressBarOfLoadingPush);
    loading.setVisibility(View.VISIBLE);
    if (isNetworkAvailable()) {
      try {
        pushButton.setEnabled(false);
        Random rand = new Random();
        int ramdom;
        Intent intentFromLogin = getIntent();
        String userID = intentFromLogin.getStringExtra(LoginActivity.userID);
        PushDataInfo pushDataInfo = new PushDataInfo();
        pushDataInfo.setTitle(
            userID
                + ":"
                + ((EditText) findViewById(R.id.notificationTitleEditText)).getText().toString());
        pushDataInfo.setUrl(
            ((EditText) findViewById(R.id.notificationLinkUrlEditText)).getText().toString());
        pushDataInfo.setAlert(
            ((EditText) findViewById(R.id.notificationMessageEditText)).getText().toString());
        ramdom = rand.nextInt((10000 - 1000) + 1) + 1000;
        pushDataInfo.setPushId(ramdom);
        getSharedPreferences("PUSHID", MODE_PRIVATE).edit().putInt("pushid", ramdom).apply();
        SimpleDateFormat currentDateAndTime = new SimpleDateFormat("dd/MM/yyyy \t kk:mm:ss");
        pushDataInfo.setDateAndTime(currentDateAndTime.format(new Date()));
        Gson gson = new Gson();
        JSONObject jsonObject = new JSONObject(gson.toJson(pushDataInfo));
        ParsePush push = new ParsePush();
        ParsePush.subscribeInBackground(userID);
        push.setChannel(userID);
        push.setData(jsonObject);
        push.sendInBackground();
        final Intent intentToMainActivity = new Intent(this, MainActivity.class);
        loading.setVisibility(View.INVISIBLE);
        AlertDialog alertDialog = new AlertDialog.Builder(this).create();
        alertDialog.setTitle("Success");
        alertDialog.setMessage("Your notification will be sent shortly !");
        alertDialog.setButton(
            AlertDialog.BUTTON_NEUTRAL,
            "OK",
            new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                finish();
                startActivity(intentToMainActivity);
              }
            });
        alertDialog.show();
      } catch (JSONException e) {

      }
    } else {
      pushButton.setEnabled(true);
      loading.setVisibility(View.INVISIBLE);
      AlertDialog alertDialog = new AlertDialog.Builder(this).create();
      alertDialog.setTitle("No Internet");
      alertDialog.setMessage("Check Network Connection and Try Again");
      alertDialog.setButton(
          AlertDialog.BUTTON_NEUTRAL,
          "OK",
          new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
              dialog.dismiss();
            }
          });
      alertDialog.show();
    }
  }
예제 #8
0
 private void sendPushNotification() {
   ParsePush push = new ParsePush();
   push.setChannel("NewCampaigns");
   push.setMessage("New campaign available!");
   push.sendInBackground();
 }