Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(push): registrationError not working on Android #1725

Merged
merged 1 commit into from
Jul 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginHandle;
import com.getcapacitor.PluginMethod;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
Expand All @@ -43,6 +44,7 @@ public class PushNotifications extends Plugin {


private static final String EVENT_TOKEN_CHANGE = "registration";
private static final String EVENT_TOKEN_ERROR = "registrationError";

public void load() {
notificationManager = (NotificationManager)getActivity()
Expand Down Expand Up @@ -87,6 +89,11 @@ public void onSuccess(InstanceIdResult instanceIdResult) {
sendToken(instanceIdResult.getToken());
}
});
FirebaseInstanceId.getInstance().getInstanceId().addOnFailureListener(new OnFailureListener() {
public void onFailure(Exception e) {
sendError(e.getLocalizedMessage());
}
});
call.success();
}

Expand Down Expand Up @@ -172,6 +179,12 @@ public void sendToken(String token) {
notifyListeners(EVENT_TOKEN_CHANGE, data, true);
}

public void sendError(String error) {
JSObject data = new JSObject();
data.put("error", error);
notifyListeners(EVENT_TOKEN_ERROR, data, true);
}

public static void onNewToken(String newToken) {
PushNotifications pushPlugin = PushNotifications.getPushNotificationsInstance();
if (pushPlugin != null) {
Expand Down