private void setupParse() { Parse.initialize(this); Parse.setLogLevel( BuildConfig.DEBUG ? Parse.LOG_LEVEL_VERBOSE : Parse.LOG_LEVEL_NONE); ParseInstallation parseInstallation = ParseInstallation.getCurrentInstallation(); parseInstallation.increment("uses"); parseInstallation.saveInBackground(); ParsePush.subscribeInBackground(""); ParsePush.subscribeInBackground("general"); ParsePush.subscribeInBackground("warning"); ParsePush.subscribeInBackground("news"); ParseLocation.registerSubclass(ParseLocation.class); Schedule.registerSubclass(Schedule.class); Price.registerSubclass(Price.class); New.registerSubclass(New.class); }
public static void setUpParse(Context context) { Parse.enableLocalDatastore(context); Parse.initialize(context, "SUA_APPLICATION_ID", "SUA CLIENT_KEY"); ParseInstallation.getCurrentInstallation().saveInBackground(); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); defaultACL.setPublicReadAccess(true); defaultACL.setPublicWriteAccess(true); ParsePush.subscribeInBackground(Constants.CHANNEL, new SaveCallback() { @Override public void done(ParseException error) { if (error == null) { Log.i(Constants.TAG, "Successfully subscribed to Parse!"); }else{ Log.i(Constants.TAG, "Error subscribed to Parse!"); } } }); }
@Override public void onCreate() { super.onCreate(); Parse.enableLocalDatastore(this); Parse.initialize(this, "b6M7rAxtdYoUgGMgGkzmYmpDWiN2T6M8c2RTJ5Zg", "Xsqyd44kUtgiOMMvwP8gyVjmdZLvXLxuynmGqqNX"); ParsePush.subscribeInBackground("Apro_2016", new SaveCallback() { @Override public void done(ParseException e) { Log.e(TAG, "Successfully subscribed to Parse!"); } }); Log.d(TAG, "not rgtd."); }
@Override public void onCreate() { super.onCreate(); ParseCrashReporting.enable(this); Parse.initialize(this, BuildConfig.PARSE_APPKEY, BuildConfig.PARSE_TOKEN); ParsePush.subscribeInBackground("wc", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.e("push", "successfully subscribed to the broadcast channel."); } else { Log.e("push", "failed to subscribe for push", e); } } }); }
@Override public void removeWC() { List<Integer> removedWCIDs = new ArrayList<>(); Collections.sort(deleteItems); for (int i = deleteItems.size() - 1; i >= 0; i--) { WordCampDB db = adapter.getItem(deleteItems.get(i)); removedWCIDs.add(db.getWc_id()); myWordCampDBs.remove((int) deleteItems.get(i)); if (!db.getTwitter().isEmpty()) { ParsePush.unsubscribeInBackground(db.getTwitter().replace("#", "")); } } deleteItems = new ArrayList<>(); communicator.removeFromMyWC(removedWCIDs); adapter = new MyWCListAdapter(myWordCampDBs, getActivity(), this); myWCLists.setAdapter(adapter); ((BaseActivity) getActivity()).refreshUpcomingFrag(); ((BaseActivity) getActivity()).refreshPastFrag(); }
@Subscribe public void getUnresponseStatus(String status) { Util.dismissLoadingDialog(); if (status.equals(DataExchange.STATUS_SUCCESS)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.you_unrespond), Toast.LENGTH_LONG).show(); PushService.unsubscribe(getApplicationContext(), DataExchange.PREFIX_FOR_CHANNEL_NAME + currentEvent.getHash()); ParsePush push = new ParsePush(); ParseQuery pushQuery = ParseInstallation.getQuery(); pushQuery.whereNotEqualTo("installationId", ParseInstallation.getCurrentInstallation().getInstallationId()); pushQuery.whereEqualTo("channels", DataExchange.PREFIX_FOR_CHANNEL_NAME + currentEvent.getHash()); push.setQuery(pushQuery); try { JSONObject data = new JSONObject("{\"action\": \"com.stepout.main.CustomReceiver.SHOW_EVENT\", \"message\": \"" + getString(R.string.user_do_not_attend_event, currentEvent.getRespondentsHash().size()) + "\", \"" + DataExchange.EVENT_HASH_FOR_VIEW_EVENT_ACTIVITY_KEY + "\": \"" + currentEvent.getHash() + "\", \"author\": \"" + currentEvent.getAuthorHash() + "\"}"); push.setData(data); } catch (JSONException e) { e.printStackTrace(); } push.sendInBackground(); Intent intentDeletion = new Intent(this, MapsActivity.class); startActivity(intentDeletion); } else if (status.equals(DataExchange.STATUS_FAIL)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.some_error), Toast.LENGTH_LONG).show(); } }
@Subscribe public void removeEventStatus(String status) { Util.dismissLoadingDialog(); if (status.equals(DataExchange.STATUS_REMOVE_SUCCESS)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.remove_success), Toast.LENGTH_LONG).show(); PushService.unsubscribe(getApplicationContext(), DataExchange.PREFIX_FOR_CHANNEL_NAME + currentEvent.getHash()); ParsePush push = new ParsePush(); ParseQuery pushQuery = ParseInstallation.getQuery(); pushQuery.whereNotEqualTo("installationId", ParseInstallation.getCurrentInstallation().getInstallationId()); pushQuery.whereEqualTo("channels", DataExchange.PREFIX_FOR_CHANNEL_NAME + currentEvent.getHash()); push.setQuery(pushQuery); push.setMessage(getString(R.string.author_deleted_event, android.text.format.DateFormat.format("dd.MM.yy hh:mm", currentEvent.getDate()))); push.sendInBackground(); Intent intent = new Intent(this, MapsActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } else if (status.equals(DataExchange.STATUS_REMOVE_FAIL)) { isRemovingProcess = false; Toast.makeText(getApplicationContext(), getResources().getString(R.string.some_error), Toast.LENGTH_LONG).show(); } }
public void notifySOS() { Log.d("AcceptedSOS","notifying"); // Find users near a given location ParseQuery<ParseUser> userQuery = ParseUser.getQuery(); userQuery.whereEqualTo("username", senderId); // Find devices associated with these users ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery(); pushQuery.whereMatchesQuery("user", userQuery); JSONObject jo = new JSONObject(); try { jo.put("title", "Someone is coming to help you!"); jo.put("alert", "Ya! I'm coming!"); jo.put("sosId", SOSid); jo.put("chatChannel", channelId); jo.put("username", ParseUser.getCurrentUser().getUsername()); jo.put("type", "helping"); jo.put("displayname", displayname); } catch (JSONException e) { e.printStackTrace(); } // Send push notification to query ParsePush push = new ParsePush(); push.setQuery(pushQuery); // Set our Installation query push.setData(jo); push.sendInBackground(); }
protected void sendPushNotifications() { ParseQuery<ParseInstallation> query = ParseInstallation.getQuery(); query.whereContainedIn(ParseConstants.KEY_USER_ID, getRecipientIds()); // send push notification ParsePush push = new ParsePush(); push.setQuery(query); push.setMessage(getString(R.string.push_message, ParseUser.getCurrentUser().getUsername())); push.sendInBackground(); }
@Override public int addToMyWC(int wcid, int position) { int retId = communicator.addToMyWC(wcid); WordCampDB wordCampDB = adapter.getItem(position); listener.onNewMyWCAdded(wordCampDB); if (!wordCampDB.getTwitter().isEmpty()) { ParsePush.subscribeInBackground(wordCampDB.getTwitter().replace("#", "")); } return retId; }
@Override public void removeMyWC(int wcid, int position) { communicator.removeFromMyWCSingle(wcid); WordCampDB wordCampDB = adapter.getItem(position); if (!wordCampDB.getTwitter().isEmpty()) { ParsePush.unsubscribeInBackground(wordCampDB.getTwitter().replace("#", "")); } listener.onMyWCRemoved(wordCampDB); }
public void onSendClicked(View view) { Message message = new Message(); message.setFromObjectId(m_me.objectId); message.setToObjectId(m_other.objectId); message.setText(etMessage.getText().toString()); message.saveInBackground(); messagesAdapter.add(message); lvMessages.setSelection(lvMessages.getCount() - 1); try { ChatNotification notification = new ChatNotification(); notification.from = m_me; notification.to = m_other; notification.text = etMessage.getText().toString(); String jsonString = new Gson().toJson(notification); JSONObject jsonObject = new JSONObject(jsonString); ParseQuery pushQuery = ParseInstallation.getQuery(); pushQuery.whereEqualTo("channels", ""); ParsePush push = new ParsePush(); push.setQuery(pushQuery); push.setData(jsonObject); push.sendInBackground(); } catch (JSONException e) { e.printStackTrace(); } etMessage.setText(""); }
@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()); }
/** * Sends a push notification to the recipient of a message. The push notification has the * following fields (in a JSONObject): * * isChat - always true * messageId - objectId of the message * messageStr - The message's string representation * fromUserId - objectId of the current user * fromUserName - username of the current user * title - title of the push notification ("New message from [username]") * alert - the notification's message (the message string) * * @param message The message to push */ private void sendPush(Message message){ ParsePush push = new ParsePush(); ParseQuery<ParseInstallation> installationQuery = ParseInstallation.getQuery(); JSONObject pushData = new JSONObject(); installationQuery.whereEqualTo("user", otherUser); try{ pushData.put("isChat", true); pushData.put("messageId", message.getObjectId()); pushData.put("messageStr", message.getMessage()); pushData.put("fromUserId", ParseUser.getCurrentUser().getObjectId()); pushData.put("fromUserName", ParseUser.getCurrentUser().getUsername()); pushData.put("title", String.format( "New message from %s", ParseUser.getCurrentUser().getUsername() )); pushData.put("alert", message.getMessage()); } catch(JSONException e){ Log.d(TAG, e.getMessage()); updateToast("JSON exception occurred", Toast.LENGTH_LONG); } push.setQuery(installationQuery); push.setData(pushData); push.sendInBackground(); }
protected void sendPushNotifications(){ //Parse installation object is used to associate users and send pushes only to intended users. ParseQuery<ParseInstallation> query = ParseInstallation.getQuery(); query.whereContainedIn(ParseConstants.KEY_USER_ID, getRecipientIds()); //send the push notification ParsePush push = new ParsePush(); push.setQuery(query); push.setMessage(getString(R.string.push_message, ParseUser.getCurrentUser().getUsername())); push.sendInBackground(); }
public static void sendOy(String username, SendCallback callback) { try { String message = "From " + ParseUser.getCurrentUser().getUsername().toLowerCase(); JSONObject data = new JSONObject("{\"action\": \"mohammad.adib.oy.UPDATE_STATUS\",\"alert\": \"" + message + "\"}"); // Send push notification to query ParsePush push = new ParsePush(); push.setChannel(username); push.setData(data); push.sendInBackground(callback); } catch (Exception e) { } }
public void sendPushNotifications() { ParseQuery<ParseInstallation> pushQuery = ParseInstallation.getQuery(); pushQuery.whereContainedIn(Constants.USER_ID, getRecipientIds()); ParsePush push = new ParsePush(); push.setQuery(pushQuery); push.setMessage(getString(R.string.message_notification,ParseUser.getCurrentUser().getUsername())); push.sendInBackground(); }
@Override public void onCreate() { super.onCreate(); // Add your initialization code here Parse.initialize(this, "H71CQB2s5TvKZkUYPAvlnAOUFg953qcY8ipvcOpA", "gnzyfpH0w5mFsBOeReXXR4ZmKYw0UrsFfvbUFqJZ"); // Also, specify a default Activity to handle push notifications in this // method as well PushService.setDefaultPushCallback(this, InitialPage.class); ParseUser.enableAutomaticUser(); ParseACL defaultACL = new ParseACL(); // If you would like all objects to be private by default, remove this // line. defaultACL.setPublicReadAccess(true); ParseACL.setDefaultACL(defaultACL, true); // Save the current Installation to Parse. ParseInstallation.getCurrentInstallation().saveInBackground(); ParsePush.subscribeInBackground("", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.d("com.parse.push", "successfully subscribed to the broadcast channel."); } else { Log.e("com.parse.push", "failed to subscribe for push", e); } } }); }
public ParsePlugin() { // Application id, client key Parse.initialize(BakerApplication.getInstance(), BakerApplication.getInstance().getString(R.string.parse_application_id), BakerApplication.getInstance().getString(R.string.parse_client_key)); ParsePush.subscribeInBackground("", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Log.d("ParsePlugin", "successfully subscribed to the broadcast channel."); } else { Log.e("ParsePlugin", "failed to subscribe for push", e); } } }); }
@Subscribe public void updateEventStatus(String status) { if (status.equals(DataExchange.STATUS_UPDATE_EVENT_SUCCESS)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.event_saved), Toast.LENGTH_LONG).show(); ParsePush push = new ParsePush(); ParseQuery pushQuery = ParseInstallation.getQuery(); pushQuery.whereNotEqualTo("installationId", ParseInstallation.getCurrentInstallation().getInstallationId()); pushQuery.whereEqualTo("channels", DataExchange.PREFIX_FOR_CHANNEL_NAME + currentEvent.getHash()); push.setQuery(pushQuery); try { JSONObject data = new JSONObject("{\"action\": \"com.stepout.main.CustomReceiver.SHOW_EVENT\", \"message\": \"" + getString(R.string.author_updated_event, currentEvent.getRespondentsHash().size()) + "\", \"" + DataExchange.EVENT_HASH_FOR_VIEW_EVENT_ACTIVITY_KEY + "\": \"" + currentEvent.getHash() + "\", \"author\": \"" + currentEvent.getAuthorHash() + "\"}"); push.setData(data); } catch (JSONException e) { e.printStackTrace(); } push.sendInBackground(); } else if(status.equals(DataExchange.STATUS_UPDATE_EVENT_FAIL)) { Toast.makeText(getApplicationContext(), getResources().getString(R.string.some_error), Toast.LENGTH_LONG).show(); } Intent intent = new Intent(this, ViewEventAsAuthorActivity.class); intent.putExtra(DataExchange.EVENT_HASH_FOR_VIEW_EVENT_ACTIVITY_KEY, currentEvent.getHash()); startActivity(intent); Util.dismissLoadingDialog(); isSavingProcess = false; }
@Override public void onCreate() { super.onCreate(); // Initialize the Parse SDK. Parse.initialize(this, BuildConfig.PARSE_APP_ID, BuildConfig.PARSE_CLIENT_KEY); // Register for Push Notifications ? SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); boolean notificationsEnabled = sharedPref.getBoolean(SettingsFragment.PREF_KEY_ENABLE_NOTIFICATIONS, true); if(notificationsEnabled){ ParsePush.subscribeInBackground("", new SaveCallback() { @Override public void done(ParseException e) { if (e == null) { Timber.d("successfully subscribed to the broadcast channel."); } else { Timber.e(e, "failed to subscribe for push"); } } }); } if (BuildConfig.DEBUG) { Timber.plant(new Timber.DebugTree()); } else { Timber.plant(new CrashReportingTree()); if (!Fabric.isInitialized()) { Fabric.with(this, new Crashlytics()); } } }
@Kroll.method public void subscribeChannel(@Kroll.argument String channel) { ParsePush.subscribeInBackground(channel); }
@Kroll.method public void unsubscribeChannel(@Kroll.argument String channel) { ParsePush.unsubscribeInBackground(channel); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ((StarterApplication)getApplication()).setMainActivity(this); ParseAnalytics.trackAppOpenedInBackground(getIntent()); ParsePush.subscribeInBackground("IRSensor", new SaveCallback() { @Override public void done(ParseException e) { } }); if (!isGooglePlayServicesAvailable()) { finish(); } createLocationRequest(); googleApiClient = new GoogleApiClient.Builder(this) .addApi(LocationServices.API) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); // init Kandy SDK!! Kandy.initialize(getApplicationContext(), "DAK35a030f39497484593f5d5372a195704", "DAS4f7751f0b9a04a9383acd3e6954edd5c"); //mainText = (TextView)findViewById(R.id.maintext); listView = (ListView) findViewById(R.id.list); pref = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); //fd= pref.edit(); Set<String> values = new HashSet<String>(); values = pref.getStringSet("numbers", values); arrayList = new ArrayList<String>(values); adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, android.R.id.text1, arrayList); listView.setAdapter(adapter); listView.setDividerHeight(3); listView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int arg2, long arg3) { arrayList.remove(arg2); adapter.notifyDataSetChanged(); //TODO: persist return false; } }); }
public void SubscribeToPushChannel(String channelName) { ParsePush.subscribeInBackground(channelName); }
public void UnsubscribeFromPushChannel(String channelName) { ParsePush.unsubscribeInBackground(channelName); }
@NonNull public static Completable subscribe(@NonNull final String channel) { return RxTask.completable(() -> ParsePush.subscribeInBackground(channel)); }
@NonNull public static Completable unsubscribe(@NonNull final String channel) { return RxTask.completable(() -> ParsePush.unsubscribeInBackground(channel)); }
@NonNull public static Completable send(@NonNull final ParsePush push) { return RxTask.completable(() -> push.sendInBackground()); }
@NonNull public static Completable send(@NonNull final JSONObject data, @NonNull final ParseQuery<ParseInstallation> query) { return RxTask.completable(() -> ParsePush.sendDataInBackground(data, query)); }
@NonNull public static Completable send(@NonNull final String message, @NonNull final ParseQuery<ParseInstallation> query) { return RxTask.completable(() -> ParsePush.sendMessageInBackground(message, query)); }