I've started using parse.com to receive push notifications in my application.
It works perfectly, but I have a couple of questions.
We perform registration, but unused channels, as follows:
ParsePush.subscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("dmode", "Oks!");
} else {
Log.e("dmode", "Fail :(", e);
}
}
});
My first question is:
I find no way to disable receiving push notifications
I searched the official documentation and stackoverflow, but I find solutions that do not work for me.
I tried:
ParsePush.unsubscribeInBackground("", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d("dmode", "unsuscribe oks");
} else {
Log.e("dmode", "unsuscribe fail", e);
}
}
});
Unsuccessfully, I have also tried:
ParsePush.unsubscribeInBackground("");
...but not work.
I'm not using channels, that is why the quotes are empty:
ParsePush.subscribeInBackground("", new SaveCallback() { //...
How I can enable and disable push notifications?
The second query is that sometimes receive duplicate notifications until two three times at once on the same device.
Someone has been the same?
Thank you very much for the help.
Greetings!
I think you should use a name for a default channel even if you are not using channels and not the empty string "".
Also have a look here Parse Question
I quote from the answer on the above link
If you called PushService.setDefaultCallback, call it again passing null as the class.
Related
I've made an app that uses Parse to send push notifications to other devices when the user is logged into his account. The problem is that the users still receive pushes even after they've logged out.
A method to fix this would be awesome.
Here's the code i use to register the device.
public void registerPushNotification() {
ParseInstallation installation = ParseInstallation.getCurrentInstallation();
installation.put("user", mCurrentUser);
installation.saveInBackground();
}
Thanks in advance!
Try this (code is in Swift, but I think it's the same)
PFUser.logOut()
PFInstallation.currentInstallation().removeObjectForKey("user")
PFInstallation.currentInstallation().saveInBackground()
Try by calling the ParseInstallation.getCurrentInstallation().deleteInBackground() at the time of logout.
I suggest using channels, with channels you can get some sort of control of pushes and so on.
The method signature is like this
ParsePush.subscribeInBackground("Name of my channel", SaveCallback cb);
Try using this when the user logs in:
ParsePush.subscribeInBackground("my_channel", new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
// Great
} else {
// Something wrong happened...
}
}
});
Use this when user logs out:
ParsePush.unsubscribeInBackground("my_channel");
When sending pushes query for all users who (are still) subscribed to the "my_channel" channel:
ParsePush push = new ParsePush();
push.setChannel("my_channel");
push.setMessage("Message to the subscribers of the channel!");
push.sendInBackground();
Make sure to check out Parse guide and docs.
Cheers!
I am getting the following exception reported in my Google Analytics for Android app.
ParseRequestException (#ParseRequest:newPermanentException:352) {main}
This is the top exception with more than 4000 hits. I am worried that some users are not able to register on parse and unable to receive push notifications. Unfortunately, I don't have any other information being reported and I am unable to replicate this on any Android devices that I have.
Here is the code, where I am initializing Parse:
Parse.initialize(this, "XXX", "YYY");
ParseInstallation.getCurrentInstallation().saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
Utils.sendException(appContext, e);
}
}
});
PushService.setDefaultPushCallback(this, ChatActivity.class);
ParsePush.subscribeInBackground(getResources().getString(R.string.parse_default_channel), new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
Toast.makeText(appContext, "Problem subscribing to the chat service. You will not be able to receive notifications!", Toast.LENGTH_LONG).show();
Utils.sendException(appContext, e);
}
}
});
When I searched for this Exception on Google, I found only 3 results and they don't have any info. I want to know:
1. If I am doing something wrong?
2. How this may be hurting my app's users?
3. How to solve this?
Thanks in advance!
I'm using Parse Android SDK v 1.9.2. Notifications are not received for the first time. But if I reinstall the App, then notifications are received.
My ApplicaitonClass
#Override
public void onCreate() {
super.onCreate();
......
Parse.initialize(this, "xxx", "xxx");
.....
}
I'm registering few additional attributes post login and doing saveInBackground ..... onCreate method
The activity is getting called and i'm seeing the logs before saveinbackground and no error on savecallback too.
.saveEventually(new SaveCallback() {
#Override
public void done(ParseException e) {
System.out.println("Done");
if (e == null) {
System.out.println("Parse --- Succesfull Registration.....");
} else {
System.out.println("Parse --- " + e);
}
}
});
But still it doesnt work on the first time, even after closing the app and starting again. However, it works if i reinstall the app.
Kindly let me know what am i doing wrongly.
After trying various examples and debugging, I finally found what i was doing wrongly. I was calling remove key from the parse defaultInstallation in order to avoid the duplicates or array.
So i need to check whether the key exists or not.
if(ParseInstallation.getCurrentInstallation().get("secretId") != null && ParseInstallation.getCurrentInstallation().get("secretId").toString().length() > 0) {
ParseInstallation.getCurrentInstallation().remove("secretId");
}
I am developing an Android application and using Parse for push notification. Currently I have a problem when registering new device. I've used the code below to subscribe my Android phone on a specific channel on Parse server.
final String channel = "myapp_" + userId;
ParsePush.subscribeInBackground(channel, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e != null) {
e.printStackTrace();
ParsePush.subscribeInBackground(channel, new SaveCallback() {
#Override
public void done(ParseException e) {
Log.e("Subscribe", e == null ? "Success" : "Failure");
}
});
} else {
Log.e("Subscribe", "Success");
}
}
});
I have a strange problem on this:
The device can be registered to Parse for the 1st time after installing apps to phone (my device has already subscribed a channel successfully) but the GCM does not return the device token. Even after I wait for a long time, but nothing good happen. Unless I quit and re-open the apps, then GCM returns device token. I don't know where is the difference between them: the 1st time using apps vs reopen apps.
Have anyone got this problem? And can you give me any suggestion to solve this?
I found the reason: the Parse registration must be proceed at onCreate action of base Application class. Then the deviceToken will be retrieved normally on Parse server.
I'm looking for some help with push notifications on Android.
Situation:
I'm trying to do a push send from an Android device, at this time for itself ( will understand later) but when I hit the send button nothing happens
Config:
Firstly, yes, the client side push is enabled.
Secondly my onCreate method in the "extends Application" class
public void onCreate() {
super.onCreate();
//Parse
//Parse.enableLocalDatastore(this);
Parse.initialize(this, "", "");
ParseObject.registerSubclass(Groups.class);
ParseObject.registerSubclass(Users.class);
//Subscribe to push
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);
}
}
});
// Save the current Installation to Parse.
ParseInstallation.getCurrentInstallation().saveInBackground();
}
My button to send the push notification ( its the basic code from the docs )
sendReqBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("Debug push onclick");
ParsePush push = new ParsePush();
push.setChannel("");
push.setMessage("The Giants just scored! It's now 2-2 against the Mets.");
push.sendInBackground(new SendCallback() {
#Override
public void done(ParseException e) {
System.out.println("Push send done");
}
});
}
});
All other settings set by the basic android tutorial (Like manifest and basic sdk adding, I already use other parse functions)
So after this code snippets added to my app I hoped that I will get a notification on the device itself as described earlier, but nothing happens. From the parse push dashboard I tried it, and it works fine (thats why I think the manifest and other things are configured well) and in the core panel on the dashboard i can see the installation in the list and the "" mark in the channels array.
Can anyone help me out?
Thanks in advance!!
Steve