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");
}
Related
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 am not sure if I am missing a step in the process of linking a Facebook account to an existing Parse User.
This is the code I am using, as per Parse.com
if (!ParseFacebookUtils.isLinked(currentUser)) {
ParseFacebookUtils.linkWithReadPermissionsInBackground(currentUser, getActivity(), null, new SaveCallback() {
#Override
public void done(ParseException ex) {
if (ex == null) {
if (ParseFacebookUtils.isLinked(currentUser)) {
Log.d("MyApp", "Woohoo, user logged in with Facebook!");
}
} else {
Log.e(TAG, ex.getMessage());
}
}
});
}
I am not receiving any type of error, and it will successfully open up the Facebook activity to accept/cancel giving access to my application. The issue that I am finding, is that the authData section inside my User record, inside Parse, is never populated.
What am I doing wrong that my Parse User is not receiving any authData?
Do you happen to add the code to fragment?
If you do that, you should consider about onActivityForResult.
As you know, onActivityForResult is not called normally.
When attempting to login and signup through Facebook, the method isNew() somehow always returns false, even if the "_User" table is empty or if the user is logging in for the first time (signing up).
According to the docs:
isNew(): Indicates whether this ParseUser was created during this session through a call to ParseUser.signUp() or by logging in with a linked service such as Facebook.
Here's the code:
private void loginWithFacebook() {
ParseFacebookUtils.logInWithReadPermissionsInBackground((Activity) getContext(), null, new LogInCallback() {
#Override
public void done(ParseUser user, ParseException e) {
if (user != null) {
if (user.isNew()) {
onLoginListener.onSignupWithFacebook();
} else {
onLoginListener.onLoginWithFacebook();
}
} else if (e != null) {
handleException(e);
}
}
});
}
Other people have come across similar problems and fixed it, but the solutions they've come up with don't apply to my case:
Facebook login with Parse always returns false in user.isNew() Android
Facebook Login not working properly (Parse)
User.isNew() returns false when it should return true
Apart from that, everything else seems to be working fine. The user data is created and stored on the table just like it normally should. Any suggestions?
remove enableAutomaticUser() if you have written in Application or BaseActivity class
docs says that this method will Enables automatic creation of anonymous users.
remove except this three and try may help you.!!
FacebookSdk.sdkInitialize(getApplicationContext());
Parse.initialize(this,getString(R.string.parse_app_id),getString(R.string.parse_client_key));
ParseFacebookUtils.initialize(this);
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.
After calling code below for several times(5-10 times), done() method for SaveCallback doesn't fire and whole application seems to stuck. It seems that this request ruins request queue and all further queries doesn't fire their callbacks either. No errors in callbacks and in logs. " BEFORE SAVING" - displayed in logs, while " SAVED" - didn't.
Do I need to change parse pricing contract, or to change my code somehow?
Log.d("MESSAGE OBJECT", " BEFORE SAVING");
messageParseObject.saveInBackground(new SaveCallback() {
#Override
public void done(final ParseException e) {
Log.d("MESSAGE OBJECT", " SAVED");
if (e != null){
completitionCallback.error(e);
return;
}
chatObject.put(ModelConstants.LAST_MESSAGE_KEY, messageParseObject);
chatObject.getRelation(ModelConstants.MESSAGES_KEY).add(messageParseObject);
chatObject.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
Log.d("CHAT OBJECT", " SAVED");
if (e == null)
completitionCallback.success();
else
completitionCallback.error(e);
}
});
}
});
Faced this and really drove me crazy. This is what I found. If the Class is already created in Parse.com, even if there is a small discrepancy saveInBackground and saveEventually fails without any error.
Best way, if this happens is to delete the created class in Parse.com and let the android SDK call it it automatically in the first invocation.
At least that did the trick for me.